为什么我无法从显示css问题的网络服务器下载xls,pdf等文件? [英] Why I am unable to download file with xls,pdf etc from webserver showing css issues?
本文介绍了为什么我无法从显示css问题的网络服务器下载xls,pdf等文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我无法下载文件(xls,pdf等)。在下载时我遇到问题是丢失文件(C:\Documents和Settings / Gridstyle.css,Stylesheet.css等关于下载word文件的问题,即使使用xls扩展名也不支持格式,adobe reader不支持类型等。
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.
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);
}
推荐答案
试试这个..
回复.ContentType =application / octet-stream;
Response.ContentDisposition =attachment;
try this..
Response.ContentType= "application/octet-stream";
Response.ContentDisposition= "attachment";
这篇关于为什么我无法从显示css问题的网络服务器下载xls,pdf等文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文