Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Why I am unable to download the files(xls,pdf etc). On downloading I am getting issue as Missing file (C:\Documents and Settings/Gridstyle.css,Stylesheet.css etc issues on downloading a word file,unsupported format even with xls extension is opened and adobe reader not in supported type etc.

C#
String ext = String.Empty;
           if (strFile.IndexOf(".") > 0)
               ext = (strFile.Split('.'))[1];

           if (ext.ToLower() == "txt")
               Response.ContentType = "text/html";
           if (ext.ToLower() == "xls")
               Response.ContentType = "xls/html";
           if (ext.ToLower() == "pdf")
               Response.ContentType = "application/pdf";

           ////combine the path and file name
           if (File.Exists(strFile))//open the file and process it
           {
               FileStream sourceFile = new FileStream(strFile, FileMode.Open, FileAccess.Read);
               long FileSize;
               FileSize = sourceFile.Length;
               Response.AddHeader("Content-Length", FileSize.ToString()); //*
               byte[] getContent = new byte[(int)FileSize];
               sourceFile.Read(getContent, 0, (int)FileSize);

               sourceFile.Close();
               Response.BinaryWrite(getContent);
           }
Posted
Comments
Sergey Alexandrovich Kryukov 19-Feb-14 4:17am    
Not clear. Downloading is totally unrelated to CSS issues, and even to the file types...
—SA

1 solution

try this..

Response.ContentType= "application/octet-stream";
Response.ContentDisposition= "attachment";
 
Share this answer
 
Comments
Rahul 105 19-Feb-14 8:29am    
The issue is after downloading and on opening word file missing file/.css msg seen. Also in pdf format type after downloading and on downloading file type not supported shown in web server. There is acrobat reader ,ms office in my system and still issue persists on doing an asp.net application from web server

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