form won't save...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?a2FyaW0=?=

    form won't save...?

    Hello,
    I have the simple code below to save text, but when I click the save btn
    the form creates the file in the C drive, but it would not save what's in the
    text box.

    Dim sw As New IO.StreamWriter ("C:\SomeFile.t xt", True)
    sw.WriteLine(tx t1.Text)

    any suggestions on why it's not saving be great.
    thanks for your help...
  • Cor Ligthert[MVP]

    #2
    Re: form won't save...?

    Hi Karim,

    The fact is that you are not closing the streamreader, that is implicitely
    done by this code.
    \\\
    Using sw As New IO.StreamWriter ("C:\SomeFile.t xt", True)
    sw.WriteLine(tx t1.Text)
    End Using
    ///

    Cor

    "karim" <karim@discussi ons.microsoft.c omschreef in bericht
    news:C202648A-BE21-4E5A-B256-605B549EC592@mi crosoft.com...
    Hello,
    I have the simple code below to save text, but when I click the save
    btn
    the form creates the file in the C drive, but it would not save what's in
    the
    text box.
    >
    Dim sw As New IO.StreamWriter ("C:\SomeFile.t xt", True)
    sw.WriteLine(tx t1.Text)
    >
    any suggestions on why it's not saving be great.
    thanks for your help...

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: form won't save...?

      "karim" <karim@discussi ons.microsoft.c omschrieb:
      I have the simple code below to save text, but when I click the save
      btn
      the form creates the file in the C drive, but it would not save what's in
      the
      text box.
      >
      Dim sw As New IO.StreamWriter ("C:\SomeFile.t xt", True)
      sw.WriteLine(tx t1.Text)
      >
      any suggestions on why it's not saving be great.
      thanks for your help...
      The stream writer uses a buffer. You can either flush the buffer by calling
      its 'Flush' method or by setting the 'AutoFlush' property. Closing the
      stream writer will flush the buffer and persist the text to disk too (see
      Cor's reply).

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

      Comment

      • kimiraikkonen

        #4
        Re: form won't save...?

        On Nov 4, 8:33 am, karim <ka...@discussi ons.microsoft.c omwrote:
        Hello,
            I have the simple code below to save text, but when I click the save btn
        the form creates the file in the C drive, but it would not save what's inthe
        text box.
        >
        Dim sw As New IO.StreamWriter ("C:\SomeFile.t xt", True)
                sw.WriteLine(tx t1.Text)
        >
        any suggestions on why it's not saving be great.
        thanks for your help...
        Hi Karim,
        As you can use StreamWriter with Using statement, you can shorten your
        code by directly calling WriteAllText method as an alternative under
        My namespace.

        My.Computer.Fil eSystem.WriteAl lText("C:\SomeF ile.txt", _
        txt1.Text, True)



        Also aware that UTF-8 is default in that method unless you specify
        other encoding as 4th argument.

        Hope this helps,

        Onur Güzel

        Comment

        Working...