Write Text File To Server

onepieceking

Well-known member
Joined
Sep 20, 2006
Messages
64
Programming Experience
1-3
Hi,

VB.NET:
'Open a file for writing
    Dim FILENAME as String = Server.MapPath("Output.txt")

    'Get a StreamReader class that can be used to read the file
    Dim objStreamWriter as StreamWriter
    objStreamWriter = File.AppendText(FILENAME)

    'Append the the end of the string, "A user viewed this demo at: "
    'followed by the current date and time
    objStreamWriter.WriteLine("A user viewed this demo at: " & DateTime.Now.ToString())
    
    'Close the stream
    objStreamWriter.Close()

I know that Server.MapPath will path the virtual path to physical path of the server. It means for the above code, it will be in "C:\Inetpub\wwwroot\Project1\".

I need the file to be in another directory called "All" in the server. Do i just write objStreamWriter = File.AppendText(C:\All\Output.txt)? Will this save the file in the client or the server?
 
ASP.Net(=Active Server Pages)/Server code is only run server-side. Webpage scripting like VBscript and Javascript is run from the Html pages client views and runs client-side. So your server code runat server. Remember server code runs in ASPNET user context and this need permission for access to folders.
 
Back
Top