Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to fix 'Access to the path 'D:\Fol_x\' is denied. error while try to download file using C# code.

Am trying to download code using C#. But am getting error,
'Access to the path 'D:\Fol_x\' is denied. Sounds like error is simple but i couldn't i tried all the solutions which i got from google but no luck.

Please help me on this. Any idea?

My Code:

<pre lang="c#">
 int idx = strfullfilePath.LastIndexOf('\\');
                    string _fileName = strfullfilePath.Substring(idx + 1); //To get file name
                    string _path = strfullfilePath.Substring(0, idx); //To get file path
                    HttpResponse res = GetHttpResponse();
                    res.Clear();
                    res.AppendHeader("content-disposition", "attachment; filename=" + _fileName);
                    res.ContentType = "application/octet-stream";
                    res.WriteFile(_path); //In this line am getting error
                    //res.Flush();
                    res.End();
Posted
Updated 16-Oct-15 4:48am
v2
Comments
ZurdoDev 16-Oct-15 10:16am    
It actually is pretty simple. Go into IIS and find the application pool for your website. Find the identity that it is running under. Give that user permissions to the path on the D drive.
Am Gayathri 16-Oct-15 10:24am    
Identity is "ApplicatioPoolIdentity" but i searched for that name in users to give permission but not found. Also i have given fullcontrol permission to everyone.
Member 11606798 16-Oct-15 11:54am    
Make sure you don't have the file open on the machine already when the application is trying to access it. That can cause access denied errors as well.
Philippe Mori 16-Oct-15 12:58pm    
Arr you sure that WriteFile take a path only and not a full file name?
Richard Deeming 16-Oct-15 13:11pm    
Looks like the answer to me - it should be res.WriteFile(strfullfilePath); instead. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900