Hi Guys,
Just having a small issue with a MemoryStream, I think my only real issue is lack of education.
I am wanting to dump a MemoryStream to a text file (.csv). Now I have some code here that does this but I'm left thinking there is a better or more elegant way to do this.
VB Code:
Private Sub StreamToFile(ByVal sFilePath As String, ByVal objStream As System.IO.MemoryStream) Dim objTxtWriter As System.IO.TextWriter = Nothing Dim objReader As System.IO.StreamReader = Nothing Try objTxtWriter = New System.IO.StreamWriter(sFilePath) objReader = New System.IO.StreamReader(objStream) objTxtWriter.Write(objReader.ReadToEnd()) objReader.Close() objTxtWriter.Close() Catch ex As Exception MessageBox.Show(ex.Message) Finally If objTxtWriter IsNot Nothing Then objTxtWriter.Dispose() objTxtWriter = Nothing End If objReader.Dispose() End Try
As you can see I am using a StreamReader to get the contents of the stream as a string and dump it. My gut feeling is that I should be able to dump this stream without using a reader?
Is the above method using a reader the only way? Can I feed a raw MemoryStream into a file??
I have done many searches but found only unlcear or incomplete answers.
Thanks PPL,
Matt.




Reply With Quote