advertisement

Find Code  Advanced Search   

Free Newsletters:   
browse free vb code
Submit Code
ASP,  HTML, and XML
Database
Dates  and Math
Files  and Directories
Forms  and Controls
Lists,  Collections, and Arrays
Miscellaneous
Multimedia/Games
Office/VBA
Network/Internet
Registry
Screen/Graphics
String  Manipulation
System/API
Windows  2000/XP
VB.NET/ASP.NET



advertisement
Read Text From/Write Text To a File (VB.NET)

Author: Intelligent Solutions Inc. (Featured Developer)
Category: VB.NET/ASP.NET
Type: Snippets
Difficulty: Beginning

Version Compatibility:  Visual Basic.NET   ASP.NET  

More information: These function allows you to retrieve a text file's contents and write text to a file in VB.NET. They also optionally provide error information if they fail. Sample Usage:

       sContents = GetFileContents("C:\test.txt", sErr)
        If sErr = "" Then
            Debug.WriteLine("File Contents: " & sContents)
            'Save to different file
            bAns = SaveTextToFile(sContents, "D:\Test.txt", sErr)
            If bAns Then
                Debug.WriteLine("File Saved!")
            Else
                Debug.WriteLine("Error Saving File: " & sErr)
            End If

        Else
            Debug.WriteLine("Error retrieving file: " & sErr)
        End If

This code has been viewed 710797 times.

Instructions: Copy the declarations and code below and paste directly into your VB project.


Declarations:

Code:

No Text Boxes

Sponsored Links