I’ve a grid that contains file list (that on another server) and download buttons for them on each row. When button clicked, file should be downloaded. When I click it on localhost, file.Exist returns true and I can download the file. However, when I try same button on server (IIS), file.Exist returns false and the file cannot be downloaded. (This server also can reach the file.) My code snippet is below;
var fileNameToShow = "8D.xls";
var fileNameAndPath = "\\10.1.101.151\Files\Live\10\8D.xls"
FileInfo file = new FileInfo(fileNameAndPath);
file.Refresh();
if (file.Exists)
{
// Send the file to the browser
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename= " + fileNameToShow + "; size=" + file.Length.ToString());
Response.TransmitFile(fileNameAndPath);
Response.Flush();
Response.End();
}
else
{
throw new Exception("File does not exist!");
}
What can I do to solve this?
Edit: File is in 10.1.101.151. IIS is in another server. My local
is also another PC.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
First, you need to set the permissions of the folder on the server, and add the server where the IIS is located to the server where the 8D.xls is located.

Second, you need to set the identity of the application pool, select a custom account, you can set the administrator.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

