By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,614 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

Writing a file to my web server

P: 1
I'm using the following c# code to write a file
Expand|Select|Wrap|Line Numbers
  1.      string strVCard = vcg.Generate();
  2.         FileInfo fi = new FileInfo("" + firstn + " " + lastn + "" + ".vcf");      
  3.         StreamWriter sw = fi.CreateText();
  4.         sw.Write(strVCard);
  5.         sw.Flush();
  6.         sw.Close();
  7.  
However this is writing the file to my local c drive in a Microsoft folder here:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

How would i change this code to use Server.MapPath to write the file to my web server as i don't have rights to write the file on the c drive?

Thanks,

Adrian.
Mar 8 '07 #1
Share this Question
Share on Google+
1 Reply


sicarie
Expert Mod 2.5K+
P: 4,677
I'm using the following c# code to write a file
Expand|Select|Wrap|Line Numbers
  1.      string strVCard = vcg.Generate();
  2.         FileInfo fi = new FileInfo("" + firstn + " " + lastn + "" + ".vcf");      
  3.         StreamWriter sw = fi.CreateText();
  4.         sw.Write(strVCard);
  5.         sw.Flush();
  6.         sw.Close();
  7.  
However this is writing the file to my local c drive in a Microsoft folder here:

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

How would i change this code to use Server.MapPath to write the file to my web server as i don't have rights to write the file on the c drive?

Thanks,

Adrian.
I'm not entirely sure (you should check this in our .Net forum), but I believe you need to set the DirectoryInfo as well as the FileInfo. Based on quickly scanning the first few docs google returned, it looks like that will allow you to set the path to your web server, and the your FileInfo will start out there.
Mar 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.