zoukankan      html  css  js  c++  java
  • Sharepoint 下载 文档库文件(转成字节下载)

    由于SharePoint和Office集成得很紧密,所以当用户采取下载副本的时候,会有一个打开按钮,当点击打开的时候可以直接打开,并直接修改文档里的内容,而不经过审批,帮采用自定义的代码来下载,让其不能在线保存,不能直接把File直接Response出去,帮需要把File转成字节输出去,下面是代码的简单示例,不是完善的代码

        SPWeb web = SPContext.Current.Web;
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["testDoc"];
                SPListItem item = list.GetItemById(3);
                string strPath = web.Url + "/" + list.RootFolder.Url + "/" + item.Name;
                //Response.Write("strPath:" + strPath + "<br/>");
                SPFile tempFile=web.GetFile(strPath);
                byte[] obj = (byte[])tempFile.OpenBinary();           
                //list.BrowserFileHandling = SPBrowserFileHandling.Permissive;
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AppendHeader("Content-Disposition", "attachment; filename= " + System.Web.HttpUtility.UrlEncode(tempFile.Name));
                Response.ContentType = "application/msword"; 
                Response.BinaryWrite(obj);
                Response.Flush();
                Response.Close(); 
  • 相关阅读:
    python中break、continue 、exit() 、pass终止循环的区别
    pandas 数据处理
    分布式爬虫
    crawlSpider全站数据爬取
    scrapy 中间件
    scrapy框架的日志等级和请求传参
    scrapy 递归解析和post请求
    scrapy管道持久化存储
    scrapy框架简介和基础应用
    高性能的异步爬虫
  • 原文地址:https://www.cnblogs.com/gzh4455/p/2654841.html
Copyright © 2011-2022 走看看