asp.net(c#)下读取word文档的方法小结
发布时间:2020-12-15 05:42:03 所属栏目:百科 来源:网络整理
导读:第一种方法: 复制代码 代码如下: Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "Application/msword"; string s=Server.MapPath("C#语言参考.doc"); Response.WriteFile("C#语言参考.doc"); Response.Write(s); Response.Flu
第一种方法: 复制代码 代码如下: 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,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,(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(); 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |