zoukankan      html  css  js  c++  java
  • asp.net 读取word 文档的方法

    第一种方法:
       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();

  • 相关阅读:
    【欧拉质数筛选法 模版】
    【归并排序 逆序对 模版】
    【 lca倍增模板】
    【LSGDOJ 1333】任务安排 dp
    【NOIP2013】火柴排队
    【USACO Feb 2014】Cow Decathlon
    【USACO08NOV】奶牛混合起来Mixed Up Cows
    【LSGDOJ 1351】关灯
    【USACO】干草金字塔
    【USACO】电子游戏 有条件的背包
  • 原文地址:https://www.cnblogs.com/suneryong/p/772115.html
Copyright © 2011-2022 走看看