DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Help Guest

    Opening a file to read.


    Hi I have realized that I have forgotten to open the file in .NET, how do
    you correctly open the file? right now I have this,
    strFile = Open InputBox("Location of File", "File Location") for append as
    1

    and it doesnt recognize Open as a valid command...Thanks


  2. #2
    VBDotNet Team [MS] Guest

    Re: Opening a file to read.

    Hi,

    You probably want to do the following:

    dim strFileName as String
    strFileName = InputBox("Location of File", "File Location")

    'To read a file
    dim fileReader as System.IO.StreamReader
    dim contents as String
    try
    fileReader = New System.IO.StreamReader(strFileName)
    contents = fileReader.ReadToEnd
    catch ex as Exception
    Msgbox (Ex.Message)
    Finally
    'Your clean up code here
    fileReader.Close
    End Try

    'To write to file
    dim fileWriter as System.IO.StreamWriter
    try
    fileWriter = new System.IO.StreamWriter(strFileName)
    fileWriter.Write("Your text")
    catch ex as Exception
    MsgBox(ex.Message)
    Finally
    'Your clean up code here
    fileWriter.Close
    End Try

    Let us know if you have more questions

    -Shamez
    VB.Net Program Manager
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Help" <Help@help.com> wrote in message news:3d108457$1@10.1.10.29...
    >
    > Hi I have realized that I have forgotten to open the file in .NET, how do
    > you correctly open the file? right now I have this,
    > strFile = Open InputBox("Location of File", "File Location") for append as
    > 1
    >
    > and it doesnt recognize Open as a valid command...Thanks
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links