zoukankan      html  css  js  c++  java
  • 通过webService下载sharepoint文档库文件

    第一、基本原理:

    1.通过对象模型得到SPItem.File得到文档库文件

    2.通过WebService将item.File.OpenBinary()返回

    3.将文件保存到服务器

    4.从服务器下载到本地

    第二、具体代码:

    WebService

    [WebMethod]
        public byte[]  GetAttachmentFileflow(string webPath,string list,int fileId) 
        {
            try
            {
                using (SPSite site = new SPSite(webPath))
                {
                    SPWeb web = site.OpenWeb();
                    SPList lists = web.Lists[list];
                    SPListItem item = lists.Items.GetItemById(fileId);
                    return item.File.OpenBinary();
                }
    
            }
            catch (Exception)
            {
                return new byte[] { };
            }
            
        }
    

    保存到服务器,下载的本地

    protected void Page_Load(object sender, EventArgs e)
        {
            File.Delete(path);
            string webPath = "http://18:8099/";
            string list = "Shared Documents";
            localhost.Service server = new localhost.Service();
            byte[] b = server.GetAttachmentFileflow(webPath, list, 1594);//1594为文件ID通过SQL取得
            File.WriteAllBytes(path, b);
        }
    
        protected void BtnClick(object sender, EventArgs e)
        {
            FileStream fileStrem = new FileStream(path, FileMode.Open);
            long fileSize = fileStrem.Length;
            Context.Response.ContentType = "application/octet-stream";//设置报文
            Context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("下载.docx", Encoding.UTF8));//下载文件名需要更改
            Context.Response.AddHeader("Content-Length", fileSize.ToString());
            byte[] fileBuffer = new byte[fileSize];
            fileStrem.Read(fileBuffer, 0, (int)fileSize);
            Context.Response.BinaryWrite(fileBuffer);
            fileStrem.Dispose();//释放资源
            Context.Response.End();
        }
    

    第三、源码:

    环境:vs2005 ,sp2007

    注:服务器端对象模型

    http://app.yinxiang.com/l/AAwg2HN1vt9HW78Q29c5fzexeu1Z-DbJh3c/

  • 相关阅读:
    VS工作目录,输出目录
    Google的C++开源代码项
    C++文件读写
    深拷贝浅拷贝
    Efficient Graph-Based Image Segmentation
    Graph Cut 简介
    Graph Cut
    "GrabCut" - Interactive Foreground Extraction using Iter
    EM算法
    Python图像处理库(2)
  • 原文地址:https://www.cnblogs.com/yixiaozi/p/4000243.html
Copyright © 2011-2022 走看看