asp.net(c#)下读取word文档的方法小结
程序员文章站
2024-03-06 22:22:20
第一种方法: 复制代码 代码如下: response.clearcontent(); response.clearheaders(); response.contentty...
第一种方法:
response.clearcontent();
response.clearheaders();
response.contenttype = "application/msword";
string s=server.mappath("c#语言参考.doc");
response.writefile("c#语言参考.doc");
response.write(s);
response.flush();
response.close();
第二种方法:
response.clearcontent();
response.clearheaders();
response.contenttype = "application/msword";
string strfilepath="";
strfilepath =server.mappath("c#语言参考.doc");
filestream fs = new filestream(strfilepath,filemode.openorcreate,fileaccess.read);
response.writefile(strfilepath,0,fs.length);
fs.close();
第三种方法:
string path=server.mappath("c#语言参考.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=文件名.doc");
response.flush();
response.binarywrite(filedata);
response.end();
复制代码 代码如下:
response.clearcontent();
response.clearheaders();
response.contenttype = "application/msword";
string s=server.mappath("c#语言参考.doc");
response.writefile("c#语言参考.doc");
response.write(s);
response.flush();
response.close();
第二种方法:
复制代码 代码如下:
response.clearcontent();
response.clearheaders();
response.contenttype = "application/msword";
string strfilepath="";
strfilepath =server.mappath("c#语言参考.doc");
filestream fs = new filestream(strfilepath,filemode.openorcreate,fileaccess.read);
response.writefile(strfilepath,0,fs.length);
fs.close();
第三种方法:
复制代码 代码如下:
string path=server.mappath("c#语言参考.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=文件名.doc");
response.flush();
response.binarywrite(filedata);
response.end();
上一篇: 教你快速实现Android动态模糊效果