Can't write to file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Microsoft

    Can't write to file

    I am trying to use the streamwriter to write to a text file

    I declare the streamwriter publically at the beginning

    im filename As String

    Dim Drive As String

    Dim oFile As System.IO.File

    Dim ofile2 As System.IO.File

    Dim nopatch As System.IO.Strea mWriter

    Dim error1 As System.IO.Strea mWriter

    Dim testfile As System.IO.Strea mWriter

    Dim dir As String





    After a button click I try to write some data ased on conditions. The files
    appear but they are empty. I check the values of the variables and they all
    of text associated



    'create the initial output files and directories

    dir = TextBox3.Text & "\"

    Directory.Creat eDirectory(dir)

    nopatch = oFile.CreateTex t(dir & "nopatch.tx t")

    error1 = ofile2.CreateTe xt(dir & "error.txt" )

    testfile = oFile.CreateTex t("C:\output\te st.txt")

    testfile.WriteL ine("test")



    Actual Write process



    Catch ex As Exception

    exout = ex.ToString

    errorout = computer & "," & servername & "," & exout

    error1.WriteLin e(errorout)

    testfile.WriteL ine("test")

    testfile.WriteL ine(errorout)

    End Try








  • Herfried K. Wagner [MVP]

    #2
    Re: Can't write to file

    * "Microsoft" <mas@mas.com> scripsit:[color=blue]
    > I am trying to use the streamwriter to write to a text file[/color]

    What doesn't work? Error message?

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Microsoft

      #3
      Re: Can't write to file

      No error messages, but I figured out that it doesn't write to the file until
      I close it. So I am using the append method followed by a close.
      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:u9SRcHtjEH A.1040@TK2MSFTN GP10.phx.gbl...[color=blue]
      > * "Microsoft" <mas@mas.com> scripsit:[color=green]
      > > I am trying to use the streamwriter to write to a text file[/color]
      >
      > What doesn't work? Error message?
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>[/color]


      Comment

      Working...