G Greg Chu Nov 22, 2004 #1 Hi, any way to send a string directly to a file on the hard drive? Thanks! Greg
G gregory_may Nov 22, 2004 #2 I have been using these for a while... May fit the bill: Public Function FILE_ReadIntoString(ByVal FileNameAndPath As String) As String Try Dim myfile As System.IO.File Dim Line As String 'Dim myStream As System.IO.FileStream If myfile.Exists(FileNameAndPath) = True Then ' Create a file to write to. Dim myStream As System.IO.StreamReader = myfile.OpenText(FileNameAndPath) FILE_ReadIntoString = myStream.ReadToEnd myStream.Close() Else App_Print("ERROR: FILE_ReadIntoString: Could not find file: " & FileNameAndPath) End If 'The problem is not so much loading files into strings as what happens next 'in the code. Adding this line should help .Net make room. GC.Collect() Catch ex As Exception FILE_ReadIntoString = "" App_Print("Error - FILE_ReadIntoString: " & ex.ToString) End Try End Function Public Function FILE_WriteFile(ByVal OutputString As String, ByVal OutputFileName As String) As Boolean Try Dim myFile As System.IO.File Dim myFileStream As System.IO.FileStream Dim myByteArray As Byte() Dim MyEncoder As New System.Text.ASCIIEncoding myFileStream = myFile.Create(OutputFileName) myByteArray = MyEncoder.GetBytes(OutputString) myFileStream.Write(myByteArray, 0, myByteArray.Length) myFileStream.Close() FILE_WriteFile = True Catch ex As Exception FILE_WriteFile = False App_Print("Error - FILE_WriteFile: " & ex.ToString) End Try End Function
I have been using these for a while... May fit the bill: Public Function FILE_ReadIntoString(ByVal FileNameAndPath As String) As String Try Dim myfile As System.IO.File Dim Line As String 'Dim myStream As System.IO.FileStream If myfile.Exists(FileNameAndPath) = True Then ' Create a file to write to. Dim myStream As System.IO.StreamReader = myfile.OpenText(FileNameAndPath) FILE_ReadIntoString = myStream.ReadToEnd myStream.Close() Else App_Print("ERROR: FILE_ReadIntoString: Could not find file: " & FileNameAndPath) End If 'The problem is not so much loading files into strings as what happens next 'in the code. Adding this line should help .Net make room. GC.Collect() Catch ex As Exception FILE_ReadIntoString = "" App_Print("Error - FILE_ReadIntoString: " & ex.ToString) End Try End Function Public Function FILE_WriteFile(ByVal OutputString As String, ByVal OutputFileName As String) As Boolean Try Dim myFile As System.IO.File Dim myFileStream As System.IO.FileStream Dim myByteArray As Byte() Dim MyEncoder As New System.Text.ASCIIEncoding myFileStream = myFile.Create(OutputFileName) myByteArray = MyEncoder.GetBytes(OutputString) myFileStream.Write(myByteArray, 0, myByteArray.Length) myFileStream.Close() FILE_WriteFile = True Catch ex As Exception FILE_WriteFile = False App_Print("Error - FILE_WriteFile: " & ex.ToString) End Try End Function
H Herfried K. Wagner [MVP] Nov 22, 2004 #3 Greg Chu said: Hi, any way to send a string directly to a file on the hard drive? Click to expand... Take a look at the 'System.IO.StreamWriter' class...
Greg Chu said: Hi, any way to send a string directly to a file on the hard drive? Click to expand... Take a look at the 'System.IO.StreamWriter' class...
C Cor Ligthert Nov 23, 2004 #4 Greg, The streamwriter/streamreader pages on MSDN are full of samples. Here the streamwriter. http://msdn.microsoft.com/library/d.../html/frlrfSystemIOStreamWriterClassTopic.asp I hope this helps, Cor
Greg, The streamwriter/streamreader pages on MSDN are full of samples. Here the streamwriter. http://msdn.microsoft.com/library/d.../html/frlrfSystemIOStreamWriterClassTopic.asp I hope this helps, Cor