Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to create a file through System.IO.FileStream of C#(in asp.net) , in the root directory of my website in the webserver(hosting webserver)or may be it's better to say root directory of website.
how it's possible?
Posted

1 solution

Something like this:

VB
string appPath = Request.PhysicalApplicationPath;
        string filePath = appPath + "Text.txt";
        StreamWriter w;
        w = File.CreateText(filePath);
        w.WriteLine("This is a test line.");
        w.WriteLine("This is another line.");
        w.Flush();
        w.Close();



Btw, I would not recommend to write it in the root of your website as the process would need write permissions. It's better to create a sub directory and write your files there.
 
Share this answer
 
v3
Comments
Saeid Mohammadpour 11-Aug-13 1:34am    
thanks of your solution,dear Manas.
but i want to write a code that works in these two situations: First) my website is my local computer(before deployment on webserver) . Second: when my website is deployed and located on webserver. when i used your solution to access my .xml file(on my own computer), following error appeared:
Could not find file 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\XMLFile1.xml'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900