1个回答
2015-04-07 · 知道合伙人互联网行家
关注
展开全部
网上方法不少,可以尝试搜索一下。
第一种方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string s=Server.MapPath("E:/wendang/wo582.doc");
Response.WriteFile("E:/wendang/wo582.doc");
Response.Write(s);
Response.Flush();
Response.Close();
第二种方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string strFilePath="";
strFilePath =Server.MapPath("E:/wendang/wo582.doc");
FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);
Response.WriteFile(strFilePath,0,fs.Length);
fs.Close();
第三种方法:
string path=Server.MapPath("E:/wendang/wo582.doc");
FileInfo file=new FileInfo(path);
FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
byte[] filedata=new Byte[file.Length];
myfileStream.Read(filedata,0,(int)(file.Length));
myfileStream.Close();
Response.Clear();
Response.ContentType="application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=wo582.doc");
Response.Flush();
Response.BinaryWrite(filedata);
Response.End();
第一种方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string s=Server.MapPath("E:/wendang/wo582.doc");
Response.WriteFile("E:/wendang/wo582.doc");
Response.Write(s);
Response.Flush();
Response.Close();
第二种方法:
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string strFilePath="";
strFilePath =Server.MapPath("E:/wendang/wo582.doc");
FileStream fs = new FileStream(strFilePath,FileMode.OpenOrCreate,FileAccess.Read);
Response.WriteFile(strFilePath,0,fs.Length);
fs.Close();
第三种方法:
string path=Server.MapPath("E:/wendang/wo582.doc");
FileInfo file=new FileInfo(path);
FileStream myfileStream=new FileStream(path,FileMode.Open,FileAccess.Read);
byte[] filedata=new Byte[file.Length];
myfileStream.Read(filedata,0,(int)(file.Length));
myfileStream.Close();
Response.Clear();
Response.ContentType="application/msword";
Response.AddHeader("Content-Disposition","attachment;filename=wo582.doc");
Response.Flush();
Response.BinaryWrite(filedata);
Response.End();
追问
能简单的描述一下这些控件运行的环境吗,谢谢学长啦!我段位太低了,试了试,在visul studio 里面,会报错,估计是哪里的环境没有配置正确呢。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询