Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > When saving file - where is it saved ?

Reply
Thread Tools

When saving file - where is it saved ?

 
 
Mr. X.
Guest
Posts: n/a
 
      01-18-2009
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


 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      01-18-2009
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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saved Mail Gone and Sent Mail Not Being Saved Gregg Firefox 6 03-06-2006 02:13 AM
Saving my saved Hotmail Emails onto disk ? Morph Computer Information 1 02-01-2005 12:10 AM
EXCEL question saving a file saving the the first column as read only Luis Esteban Valencia ASP .Net 0 01-06-2005 07:02 PM
Automatically controlling where a file will be saved based on file extension and/or origin Daniel Prince Firefox 6 12-11-2004 10:58 PM
Saving DataTable to session vs saving a Custom object. John Kandell ASP .Net 4 12-10-2004 05:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57