Last post Oct 31, 2017 09:56 AM by Cathy Zou
Oct 30, 2017 06:30 AM|ludek_aspnet|LINK
on file server is shared directory with excel files - \\fileserver\share\file1.xls.
How open this file from asp.net page on client pc with client excel application.
Oct 30, 2017 12:03 PM|PatriceSc|LINK
The usual approach would be to serve the file content using the attachment content-disposition to trigger a download dialog. For example
https://forums.asp.net/t/1302436.aspx?Downloading+Attachment+using+Response+AddHeader+content+disposition+attachment (you could also use a ASHX Handler).
Or do you mean that \\fileserver\share can be accessed directly by users. It might be possible but could require adiministering the browser configuration at the enterprise level as nowadays and by default most if not
all browsers won't allow to use the file protocol from an http page. So IMO use solution #1 unless you see a really strong benefit in doing otherwise.
Oct 31, 2017 09:56 AM|Cathy Zou|LINK
From your description, your excel file stored on shared directory. So, if you only want user to read the file, you could refer to the code as below:
protected void Button1_Click(object sender, EventArgs e)
string fileName = "file1.xls";
string inputPath = @"C:\Users\JingjingCai\Desktop\share\file1.xls";
string rootPath = Server.MapPath("~/");
string outputPath = inputPath.Replace(rootPath, "/").Replace("\\", "/");
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/octet-stream";
////////////the same way without Server.MapPath
string directory= @"C:\Users\JingjingCai\Desktop\share\";
string filePath = directory + "file1.xls";
Response.ContentType = "Application/vnd.ms-excel";
"attachment; filename=" + "file1.xls");
However, when multiple users modify the excel file at the same time, it will cause some conflicts. So, if you meet the this situation, you need to add lock to the process.