Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to path "myPath" denied 1

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Hi guys,
I'm creating a site that allows users to download report files. The files are created at run time based on user selections. I created a folder within the root of my site called "\TempRprts" and what I'm trying to do is (1) save the report file (created based on user criteria) to the "\TempRprts" folder, (2) upload the file to the user's computer using Response.WriteFile, and (3) once the user has download the file to his machine, delete it from the "\TempRprts" folder. I have the following code:
Code:
[COLOR=blue]string[/color] fileName = "MyFile.pdf";
[COLOR=blue]string[/color] fileSave = [COLOR=blue]this[/color].MapPath("TempRprts\\" + 
   fileName);
[COLOR=blue]string[/color] contentString = "attachment; " +
   "fileName=\"" + fileName + "\"";

Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", contentString);
[b][COLOR=red]Response.WriteFile(fileSave);[/color][/b]
Response.End();
The bold red line above produces the error: Access to the path "c:\inetpub\ is denied. I went ahead and assigned Write permissions to the root folder of my site and also to the c:\inetpub\ folder and I still get the same error. Can anybody tell me what the problem is?

By the way, if I change the folder I'm trying to save the temporary file to from this.MapPath("TempRprts\\" + fileName) to "C:\\" + fileName, everything works fine. But of course, I wouldn't want to use the C drive of my server to write temporary files, or would I?

Can anybody please point me in the right path?

Thanks!

JC


We don't see things as they are; we see them as we are. - Anais Nin
 
Come on guys, anyone?

We don't see things as they are; we see them as we are. - Anais Nin
 
stsuing,
Thanks for your reply.

The article was very helpful but it did not answer my question. I need to be able to save a file to a folder within my site. It's not working and I get the error "access to ... denied." Any ideas on how I could make it work?

Thanks!

JC

We don't see things as they are; we see them as we are. - Anais Nin
 
Not sure.
Maybe
System.Web.HttpContext.Current.Server.MapPath(your file);
Marty
 
Guys, thanks for your replies.

yu217171 - you were right on the money!

JC

We don't see things as they are; we see them as we are. - Anais Nin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top