ashutosh raina
ashutosh raina

Reputation: 9314

how to save a file at the server in asp.net?

i have a log file which needs to be written to the server . If i had the code in a code behind file for a web form i would have done this

File.WriteAllText(Server.MapPath("/ErrorLogFile/ErrorLogFile.log"),json);

Now, since my code sits inside the App_Code folder i have no access to the Server class ...so i have to tell it to go find the folder and then write it to the disk. I can accomplish this by telling it the full path and it will work . but i want to tell it to go look for the ErrorLogFolder in the directory you are in and then write the file there . Is there a way to do that ?

Upvotes: 1

Views: 3241

Answers (2)

Lloyd
Lloyd

Reputation: 2942

System.Web namespace, HttpContext exposes the same functionality from your "code" files.

HttpContext.Current.Server.MapPath("STRING VALUE");

Upvotes: 1

Nick Rolando
Nick Rolando

Reputation: 26177

If your using the App_Code resources from your code-behind, just pass the path to the function in your App_Code

appCodeClass.callFunc(Server.MapPath("/ErrorLogFile/ErrorLogFile.log"), arg2, arg3, ..);

Upvotes: 1

Related Questions