Läser in hela filen i en variabel – VB.net

Läser in hela filen i en variabel – VB.net

Public Function GetFileContents(ByVal FullPath As String, _
Optional ByRef ErrInfo As String = “”) As String

Dim strContents As String
Dim objReader As StreamReader
Try

objReader = New StreamReader(FullPath)
strContents = objReader.ReadToEnd()
objReader.Close()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
End Function

Spara enkelt ner i textfil – VB.net

Så här sparar man enkelt ner något i txt-filer i VB.net

 

 

Public Function SaveTextToFile(ByVal strData As String, _

ByVal FullPath As String, _

Optional ByVal ErrInfo As String = “”) As Boolean

Dim Contents As String

Dim bAns As Boolean = False

Dim objReader As StreamWriter

Try

objReader = New StreamWriter(FullPath)

objReader.Write(strData)

objReader.Close()

bAns = True

Catch Ex As Exception

ErrInfo = Ex.Message

End Try

Return bAns

End Function

Lista kataloger i VB.net

Så här listar man kataloger i VB.net:

 

files = System.IO.Directory.GetDirectories(FolderBrowserDialog1.SelectedPath)

For Each fname As String In files

MsgBox(fname)

Next