zoukankan      html  css  js  c++  java
  • Add a file to a Document Library and update metadata properties in a single method添加文档的方法

    private void AddFileToDocumentLibrary(string documentLibraryUrl, string filename, byte[] file_bytes, string itemTitleText)
         {
             SPSecurity.RunWithElevatedPrivileges(delegate()
             {
                 using (SPSite site = new SPSite(documentLibraryUrl))
                 {
                     using (SPWeb web = site.OpenWeb())
                     {
                         web.AllowUnsafeUpdates = true;
                         SPDocumentLibrary documentLibrary = (SPDocumentLibrary)web.Lists["MyDocumentLibraryName"];
                         SPFileCollection files = documentLibrary.RootFolder.Files;
                         SPFile newFile = files.Add(documentLibrary.RootFolder.Url + "/" + filename, file_bytes, true);
     
                         SPList documentLibraryAsList = web.Lists["MyDocumentLibraryName"];
                         SPListItem itemJustAdded = documentLibraryAsList.GetItemById(newFile.ListItemAllFields.ID);
                         SPContentType documentContentType = documentLibraryAsList.ContentTypes["Document"]; //amend with your document-derived custom Content Type
                         itemJustAdded["ContentTypeId"] = documentContentType.Id;
                         itemJustAdded["Title"] = itemTitleText;
                         //set other propeerties here..
                         itemJustAdded.Update();
                         newFile.CheckIn("New", SPCheckinType.OverwriteCheckIn);
                         web.AllowUnsafeUpdates = false;
                     }
                 }
             });
         }
  • 相关阅读:
    (转)使用InfluxDB+cAdvisor+Grafana配置Docker监控
    Linux cut命令
    php 三种数组
    Linux httpd源码编译安装
    Linux yum如何下载rpm包到本地
    linux yum 工具
    windows phpstudy 本地添加自定义域名
    php.ini
    Linux rpm 查询
    linux rpm 安装和卸载
  • 原文地址:https://www.cnblogs.com/sunjunlin/p/4073901.html
Copyright © 2011-2022 走看看