Link to home
Start Free TrialLog in
Avatar of rocky050371
rocky050371

asked on

Memory Stream

I am saving a file in the database, I need to be able to allow the user to edit the file then save it back away.

I also need to know how to launch a file from a memory stream

This allows the user to save the memory file to a location, I really need an edit option

     Using ms = New MemoryStream(_document.MergeDocument, False)

            Using fs = File.Open(String.Format("{0){1}", Path.GetTempPath, uteFilename.Text), FileMode.Create, FileAccess.Write)
                ms.WriteTo(fs)
            End Using

        End Using
Avatar of kaufmed
kaufmed
Flag of United States of America image

Edit it how? You don't have to write out the MemoryStream to a file in order to be able to edit it. If the data is small enough, you could keep the data in a string variable and edit that, writing the changes back to the DB when finished.

As far as "to launch a file from a memory stream," if you mean you have an executable in the MemoryStream (i.e. binary data), you could write the data out to a temporary file and then use Process.Start to execute it. There are probably ways to execute without writing out to a file, but IMO this would be the simplest way to execute.
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And if you want to allow a third party program such as MS Word to modify the file and save it back then you would need to do some work. Word can not open the file from memory stream within your program. You would need to save the file to disk, launch the program, monitor it, and when program closes, see if changes have been made and update the file in DB.
To be a little more clear I think:
Private Sub Test()
    EditMyFile("Hi.doc", MyFileByteArray)
End Sub

Open in new window

Based in your example, maybe you can use the EditMyFile method in this way:
Private Sub Test()
    EditMyFile(uteFilename.Text, _document.MergeDocument)
End Sub

Open in new window