将文档从客户端对象模型上传到SharePoint列表 [英] Upload a document to a SharePoint list from Client Side Object Model

查看:198
本文介绍了将文档从客户端对象模型上传到SharePoint列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用.NET(C#)中的客户端对象模型将文档上载到SharePoint列表或文件夹。什么是最好的方法来做到这一点?

要求如下:


  • 设置元数据值


  • 必须使用超过列表视图阈值的库

  • 上传文档到Sharepoint文档库使用Client对象中的以下功能模型:
    $ b $ pre $ public void UploadDocument(字符串siteURL,字符串documentListName,
    字符串documentListURL,字符串documentName,

    byte [] documentStream)
    {

    using(ClientContext clientContext = new ClientContext(siteURL))
    {

    // Get Document列出
    列出documentsList = clientContext.Web.Lists.GetByTitle(documentListName);

    var fileCreationInformation = new FileCreationInformation();
    //分配给内容byte [],即documentStream

    fileCreationInformation.Content = documentStream;
    //允许写入文档

    fileCreationInformation.Overwrite = true;
    //上传URL

    fileCreationInformation.Url = siteURL + documentListURL + documentName;
    Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
    fileCreationInformation);

    //更新名称为DocType的字段的元数据
    uploadFile.ListItemAllFields [DocType] =收藏夹;

    uploadFile.ListItemAllFields.Update();
    clientContext.ExecuteQuery();





    $ p $以下链接也对你有帮助
    1) http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx



    2) http://msdn.microsoft.com/en-us/library/ee956524.aspx



    3) http://www.codeproject.com/Articles/103503/如何-to-upload-download-a-document-in-SharePoint-20

    I need to upload a document to a SharePoint list or folder using the Client Side Object Model from .NET (C#). What is the best way to do this?

    The requirements are as follows:

    • Set metadata values

    • No limitation on file size

    • Must work with libraries that exceed the List View Threshold

    解决方案

    For Uploading Document to Sharepoint Document Library use Following function in Client Object Model:

    public void UploadDocument(string siteURL, string documentListName,
    string documentListURL, string documentName,
    
    byte[] documentStream)
    {
    
    using (ClientContext clientContext = new ClientContext(siteURL))
    {        
    
    //Get Document List
    List documentsList = clientContext.Web.Lists.GetByTitle(documentListName);
    
    var fileCreationInformation = new FileCreationInformation();
    //Assign to content byte[] i.e. documentStream
    
    fileCreationInformation.Content = documentStream;
    //Allow owerwrite of document
    
    fileCreationInformation.Overwrite = true;
    //Upload URL
    
    fileCreationInformation.Url = siteURL + documentListURL + documentName;
    Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(
        fileCreationInformation);
    
    //Update the metadata for a field having name "DocType"
    uploadFile.ListItemAllFields["DocType"] = "Favourites";
    
    uploadFile.ListItemAllFields.Update();
    clientContext.ExecuteQuery();
    
    }
    }
    

    Following link is Also Helpful For you 1) http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

    2)http://msdn.microsoft.com/en-us/library/ee956524.aspx

    3)http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20

    这篇关于将文档从客户端对象模型上传到SharePoint列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆