gesamten ordner in ein file stecken???

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von developsoftware.

    ich will eein file machen mit der endung itp. ok das hab ich hingekriegt.aber jetz benutze ich das hier zum speichern von denn daten:

    ImageDatas:

    VB.NET-Quellcode

    1. <Serializable()> _
    2. Public Class ImageDatas
    3. #Region "Declarations"
    4. Private iBackground As Bitmap
    5. Private iLockBackground As Bitmap
    6. Private iResources() As Byte
    7. #End Region
    8. #Region "Properties"
    9. Public Property Background() As Bitmap
    10. Get
    11. Return iBackground
    12. End Get
    13. Set(ByVal value As Bitmap)
    14. iBackground = value
    15. End Set
    16. End Property
    17. Public Property LockBackground() As Bitmap
    18. Get
    19. Return iLockBackground
    20. End Get
    21. Set(ByVal value As Bitmap)
    22. iLockBackground = value
    23. End Set
    24. End Property
    25. Public Property Resources() As Byte()
    26. Get
    27. Return iResources
    28. End Get
    29. Set(ByVal value As Byte())
    30. iResources = value
    31. End Set
    32. End Property
    33. #End Region


    so normalerweise geht das dann so :

    VB.NET-Quellcode

    1. id = New ImageDatas
    2. id.Background = PictureBoxBackground.Image
    3. id.LockBackground = PictureBoxLockbackground.Image
    4. Project.Serialize(ProjectName & ".itp", id)


    das serializieren das ist das hier:

    VB.NET-Quellcode

    1. Sub Serialize(ByVal strPath As String, ByVal myProps As ImageDatas)
    2. ' create a filestream to allow saving the file after it has
    3. ' been serialized in this method
    4. Dim fs As New FileStream(strPath, FileMode.OpenOrCreate)
    5. ' create a new instance of the binary formatter
    6. Dim formatter As New BinaryFormatter
    7. Try
    8. ' save the serialized data to the file path specified
    9. formatter.Serialize(fs, myProps)
    10. fs.Close()
    11. Catch ex As SerializationException
    12. MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
    13. End Try
    14. End Sub
    15. Public Function Deserialize(ByVal strPath As String) As ImageDatas
    16. ' create filestream allowing the user to open an existing file
    17. Dim fs As New FileStream(strPath, FileMode.Open)
    18. ' create a new instance of the Personal Data class
    19. Dim myProps As ImageDatas
    20. myProps = New ImageDatas
    21. Try
    22. ' create a binary formatter
    23. Dim formatter As New BinaryFormatter
    24. ' deserialize the data stored in the specified file and
    25. ' use that data to populate the new instance of the personal data class.
    26. myProps = formatter.Deserialize(fs)
    27. fs.Close()
    28. ' return the deserialized data back to the calling application
    29. Return myProps
    30. Catch ex As SerializationException
    31. MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
    32. Return myProps
    33. End Try
    34. End Function


    so und jetz will ich die resourcen aus einem ordner in mein file speichern.

    nur wie geht das????
    moment, geht es jetzt um Resourcen im Programm oder einen gewöhnlichen Dateiordner? Beim gewöhnlichen Dateiordner halt am besten in die Datei erst nen Index schreiben, und per ReadAllBytes/WriteAllBytes dann die einzelnden Dateien in die eine Datei packen. Auslesen dann anhand des Indexes
    Ist sehr einfach, wie bereits gesagt, entweder Binarywriter und irgendwelche Trennzeichen verwenden, oder vllt. noch besser Base64 und Streamwriter/reader. Lässt sich auch noch mit einem GZIP-Stream kombinieren, dann wär das ganze sogar noch komprimiert.