Reputation: 57
I'm working on a web app that runs Excel reports and I'm using an Excel template file that's saved on the server. It works fine when I run it locally but when I try to run the Excel report on the server I get an error saying access is denied to the template file that's saved in the same directory, but I can download the template file when I navigate to it in the browser.
I granted everyone full access to the file to see if that was the issue but I still get the error. What am I overlooking?
error errorId="05d6462e-8bb5-401d-85bc-cd4d9e36fc90" application="/LM/W3SVC/8/ROOT" host="USFLWCT0" type="System.UnauthorizedAccessException" message="Access to the path '\usflwct0\D$\SherlockRoot\Files\Volume_by_Week_Template.xlsx' is denied." source="mscorlib" detail="System.UnauthorizedAccessException: Access to the path '\usflwct0\D$\SherlockRoot\Files\Volume_by_Week_Template.xlsx' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at
edit: Here's the code used to open the file. The path is hardcoded for now
using (var template = System.IO.File.OpenRead(@"\\usflwct0\D$\SherlockRoot\Files\Volume_by_Week_Template.xlsx"))
Upvotes: 1
Views: 322
Reputation:
If you want the application to read the the template file, put it in the App_Data folder
Upvotes: 0
Reputation: 119146
You are using one of the admin shares that Windows creates for each drive, in this case the D$
share. They are only accessible by admin level users. You should share the folder you want directly, for example, share the D:\SherlockRoot\Files
folder as SherlockFiles
that was you can access the content like this \\usflwct0\SherlockFiles\Volume_by_Week_Template.xlsx
or in code:
var file = @"\\usflwct0\SherlockFiles\Volume_by_Week_Template.xlsx"
using (var template = System.IO.File.OpenRead(file))
Upvotes: 1