When saving file - where is it saved ?

Discussion in 'ASP .Net' started by Mr. X., Jan 18, 2009.

  1. Mr. X.

    Mr. X. Guest

    Helo,

    For the code (The code is the code-behind an aspx page) :
    '**************************************************

    Dim fileName As String

    Dim st As System.IO.StreamWriter

    filename = "a.txt"

    st = New System.IO.StreamWriter(fileName)

    st.Write("this is a text")

    st.Close()

    st = Nothing

    '**************************************

    The above code runs, there is not any file created.

    How can I save (and load) a file, and just putting simple text on it ?

    Thanks :)
    Mr. X., Jan 18, 2009
    #1
    1. Advertising

  2. I believe it is created in the current directory. However, it is bad
    programming practice to give just a filename. Try something like the
    following:


    Private Sub btnCreateText_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnCreateText.Click
    'CreateText either creates or overwrites
    Dim texttestwriter As StreamWriter =
    File.CreateText(Server.MapPath("TextTest.txt"))
    Dim writetime As Date = Date.Now
    texttestwriter.WriteLine("This line was written at {0} {1}",
    writetime.ToShortDateString(), writetime.ToLongTimeString())
    texttestwriter.Close()
    End Sub

    Private Sub btnAppendText_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnAppendText.Click
    'AppendText either creates or appends
    Dim texttestwriter As StreamWriter =
    File.AppendText(Server.MapPath("TextTest.txt"))
    Dim writetime As Date = Date.Now
    texttestwriter.WriteLine("This line was written at {0} {1}",
    writetime.ToShortDateString(), writetime.ToLongTimeString())
    texttestwriter.Close()
    End Sub


    Notice that when declaring and creating my StreamWriters I do not use the
    StreamWriter constructor and I also use the Server.MapPath(filename)
    function. If you have any more questions, feel free to ask. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Mr. X." <no_spam_please@nospam_please.com> wrote in message
    news:...
    > Helo,
    >
    > For the code (The code is the code-behind an aspx page) :
    > '**************************************************
    >
    > Dim fileName As String
    >
    > Dim st As System.IO.StreamWriter
    >
    > filename = "a.txt"
    >
    > st = New System.IO.StreamWriter(fileName)
    >
    > st.Write("this is a text")
    >
    > st.Close()
    >
    > st = Nothing
    >
    > '**************************************
    >
    > The above code runs, there is not any file created.
    >
    > How can I save (and load) a file, and just putting simple text on it ?
    >
    > Thanks :)
    >
    Nathan Sokalski, Jan 18, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Kandell
    Replies:
    4
    Views:
    4,156
    eeebop
    Dec 10, 2004
  2. Luis Esteban Valencia
    Replies:
    0
    Views:
    2,508
    Luis Esteban Valencia
    Jan 6, 2005
  3. =?Utf-8?B?TWFya3VzUG9laGxlcg==?=

    Saved HTM File not displayed correctly

    =?Utf-8?B?TWFya3VzUG9laGxlcg==?=, Aug 1, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    648
    Joerg Jooss
    Aug 1, 2005
  4. SL
    Replies:
    2
    Views:
    459
    S. Justin Gengo
    Dec 12, 2005
  5. Lovely Angel For You

    Saving Images While Saving ASP Pages !

    Lovely Angel For You, Oct 2, 2003, in forum: ASP General
    Replies:
    1
    Views:
    206
    Curt_C [MVP]
    Oct 3, 2003
Loading...

Share This Page