### Textfile to and from String

'Read the content of a textfile to a string. A list and stringbuilder is used to ensure proper CRLF handling.
'Returns the file content as string or an error message if the file can not be opned
'Example: fx.Clipboard.SetString(File2String(File.DirApp, "myfile.txt"))
`Private Sub File2String(folder As String, filename As String) As String 'ignore
Dim result As String = ""
Dim sb As StringBuilder
sb.Initialize
Try
Dim l As List = File.ReadList(folder,filename)
For i = 0 To l.Size - 1
sb.Append(l.Get(i) & CRLF)
Next
result = sb.ToString
Catch
result = LastException.Message
End Try
Return result
End Sub`
'Save a string to a textfile
`Private Sub String2File(folder As String, filename As String, content As String) 'ignore
Dim fc As FileChooser
fc.Initialize
fc.InitialDirectory = folder
fc.InitialFileName = filename
fc.Title = "Save File"
Dim f As String = fc.ShowSave(MainForm)
If f.Length = 0 Then Return
Try
File.WriteString(GetFilePath(f), GetFileName(f), content)
Catch
Log("Save File Error: " & LastException.Message)
End Try
End Sub`

Changed: , Category: Files, File: T6C193M1399.htm, ID: 1399