2

I have an asp.net app and I am trying to save a text file to a folder that changes with each client. How can I write it to save the files to a folder that changes. For example one customer might be C:\inetpub\wwwroot\site1\ another might be C:\inetpub\wwwroot\site2. Relative paths don't seem to work, and I've tried GetCurrentDirectory but it kept giving me the wrong directory.

Thanks

jumbojs
  • 4,768
  • 9
  • 38
  • 50

3 Answers3

2

You should try :

In the *.aspx.cs file :

string currentPath = Server.MapPath("~");

I don't have the tools to test here, but I think the code is right.

Julien N
  • 3,880
  • 4
  • 28
  • 46
0

Take a look at Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME")).

Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
  • That doesn't guarantee that is the folder location at the client though. There was no indication of whether or not it would be in a folder that represents the client's site. – casperOne Jan 06 '09 at 17:44
0

You should add a value to the web.config file which is set to the path where the file is saved.

Then, in you code, retrieve this value from the documentation, and use that path when saving.

casperOne
  • 73,706
  • 19
  • 184
  • 253