Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top