Home > DeveloperSection > Forums > Write to the file system in a directory
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    October-07-2013 8:55 AM

 C# C# 

 1 Reply(s)
 1145  View(s)
Rate this:

I would like to write to the file system in a directory C: \ directory name, for the moment I have this code:

if (! System.IO.File.Exists (HttpContext.Current.Server.MapPath (filename)))
   TXTFile = new System.IO.StreamWriter (HttpContext.Current.Server.MapPath (filename));
   TXTFile = System.IO.File.AppendText (HttpContext.Current.Server.MapPath (filename));

but in this way writes on the application folder. How to fix it?

Manoj Bhatt
Manoj Bhatt

Total Post:154

Posted on    October-08-2013 1:10 AM

You can do:

Path.Combine(@"C:\", filename)

instead of

HttpContext.Current.Server.MapPath (filename)
Ensure your application has write access to the destination.

Don't want to miss updates? Please click the below button!

Follow MindStick