Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:


In My Page I have Used Link Button. On Click of that link button I am redirecting user to
Corresponding Address where data is saved
But Its working only in chrome
in Firefox the extension of File is always .aspx


So Basically what i want to ask is this Coding Error or problem of browser
Updated I have Checked in Firebug and didn't find any error.

My Code is
C#
 tenderDetail = BLLTender.GetTenderDetail(long.Parse(Request.QueryString["TenderID"]));
 var FileName = tenderDetail.TechDoc;
if (File.Exists(Server.MapPath("Document/" + FileName)))
 {
     var path = Server.MapPath(Server.MapPath("Document/" + FileName));
     var Extension = Path.GetExtension(path);
     var client = new WebClient();
     var buffer = client.DownloadData(path);
     switch (Extension)
     {
         case ".docx":
         case ".doc":
             Response.ContentType = "Application/msword";
             Response.AddHeader("content-length", buffer.Length.ToString(CultureInfo.InvariantCulture));
             Response.BinaryWrite(buffer);
             break;
         case ".xlsx":
         case ".xls":
             Response.ContentType = "Application/x-msexcel";
             Response.AddHeader("content-length", buffer.Length.ToString(CultureInfo.InvariantCulture));
             Response.BinaryWrite(buffer);
             break;
         case ".pdf":
             Response.ContentType = "application/pdf";
             Response.AddHeader("content-length", buffer.Length.ToString(CultureInfo.InvariantCulture));
             Response.BinaryWrite(buffer);
             break;
         case ".zip":
         case ".rar":
             Response.ContentType = "application/zip";
             Response.AddHeader("content-length", buffer.Length.ToString(CultureInfo.InvariantCulture));
             Response.BinaryWrite(buffer);
             break;
     }
 }


After Searching on net I have found i should create a page on which i provide downloading link
so i change my code to this but still in case of .xls in firefox it comes with unknown extension
C#
var fileName = Request.QueryString["name"];
Response.Clear();
// Clear the content of the response
Response.ClearContent();
Response.ClearHeaders();

// Buffer response so that page is sent
// after processing is complete.
Response.BufferOutput = true;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.TransmitFile(Server.MapPath("~/Document/" + fileName));
Response.End();
Posted
Updated 15-Dec-13 22:54pm
v4
Comments
JoCodes 14-Dec-13 7:14am    
Any error you are getting?Where is the redirecting here?
V1CT0R. 14-Dec-13 7:40am    
the error is in Firefox the extension of all document is .aspx
it is redirecting where file is saved
JoCodes 14-Dec-13 7:58am    
Have checked in firebug about the issue?
V1CT0R. 14-Dec-13 8:36am    
Ya I have and didn't get any problem

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