Results 1 to 2 of 2

Thread: [2005] streamWriter giving error 'Access Denied' to files created already

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Australia
    Posts
    237

    [2005] streamWriter giving error 'Access Denied' to files created already

    If I have

    Code:
    Private Sub myform_load(byVal sender As Object, byVal e As EventArgs) Handles MyBase.load
    Dim sw As New StreamWriter("myurl") 'this will create file in debug folder
    sw.write("Sup yo")
    sw.close()
    End Sub
    If I run that again, will that erase the previous file created? or will it just edit it and write 'Sup yo' in it?

    If so can someone tell me how to write to a file that exists already?

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] streamWriter giving error 'Access Denied' to files created already

    Check out the 2nd overload, it specifies if you want to append or not. If set to True then it will simply add text. If false, it will overwrite. Don't forget the file extension either. And if using 2005, then you can implement "Using" which will dispose of the streamwriter for you after.
    2 Code:
    1. Using sw As New IO.StreamWriter("myurl.txt", True) 'this will create file in debug folder
    2.        sw.Write("Sup yo")
    3.        sw.Close()
    4. End Using
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width