Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using ExcelReaderFactory for reading excel file without saving on server, When I run the code with VS(ie Ctrl+F5) it works fine, but when I publish it on server(or even local IIS) it gives error
C#
Access to the Path 'path of my file' is denied

Below is my code

C#
public void UploadFile(HttpPostedFile file)
{
FileStream stream = File.Open(file.FileName, FileMode.Open, FileAccess.Read);
 IExcelDataReader excel= ExcelReaderFactory.CreateBinaryReader(stream);  

}


Can anyone suggest some alternate code for implementing this?
Posted

The error is clear, it's a permissions issue. This means you need to look at the identity of the application pool in IIS that is hosting your site and then grant write permissions to that user to the directory where you are trying to save the files.
 
Share this answer
 
In normal scenario, web server should not have access on client's file structure.
just try to visualize the implications, if this security measure is not in place.
Any website you may open could read all files on your machine.

the best possible approach (if you don't want to store the file on server) is to save the file on webserver, read it and then delete it.
 
Share this answer
 

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