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;
                 }
             }
         });
     }
时间: 2024-08-30 10:57:20

Add a file to a Document Library and update metadata properties in a single method添加文档的方法的相关文章

Umbraco(1) - Document Types(翻译文档)

Document Types Data first nothing in = nothing out! 任何网站的第一步是创建一个"Document Type"-几次安装后你会熟悉这个术语,但一开始可能有点令人困惑.Document Type在Umbraco中是一个数据容器,您可以添加数据字段/属性,编辑用户可以在其中输入数据和Umbraco中还可以使用它来输出相关部分"template"(稍后详细介绍这些). Document Types是无限扩展的,但是通常你会

Document类型[第10章-文档对象模型DOM 笔记2]

Document 类型 JavaScript 通过 Document 类型表示文档.在浏览器中, document 对象是 HTMLDocument (继承自 Document 类型)的一个实例,表示整个 HTML 页面.而且, document 对象是 window 对象的一个属性,因此可以将其作为全局对象来访问. Document 类型可以表示 HTML 页面或者其他基于 XML 的文档.不过,最常见的应用还是作为HTMLDocument 实例的 document 对象.通过这个文档对象,不

第10章 文档对象模型DOM 10.2 Document类型

Document 类型 JavaScript 通过 Document 类型表示文档.在浏览器中, document 对象是 HTMLDocument (继承自 Document 类型)的一个实例,表示整个 HTML 页面.而且, document 对象是 window 对象的一个属性,因此可以将其作为全局对象来访问. Document 类型可以表示 HTML 页面或者其他基于 XML 的文档.不过,最常见的应用还是作为HTMLDocument 实例的 document 对象.通过这个文档对象,不

有关文档碎片(document fragment)的用法

通常情况下修改.删除或者增加DOM元素.更新DOM会导致浏览器重新绘制屏幕,也会导 致reflow,这样会带来巨大的开销.我们通常解决这的办法尽量减少更新DOM,这也就意 味着将DOM的改变分批处理,并在"活动"文档树之外执行这些更新. 当需要创建一个相对比较大的子树,应该在子树完全创建之后再将子树添加到DOM树中, 这时采用文档碎片技术来容纳所有的节点. //反例子 //在创建时立即添加节点 var p,t; p = document.createElement('p'); t =

SharePoint 2007 (MOSS/WSS) - how to remove "Download a Copy" context menu from a Document Library

One of my friend and colleague asked me this question. I found it tricky and a good post for my blog. Here is what you have to do: Go to your 12 hive\TEMPLATE\LAYOUTS\1033 folder. Open up the Core.js file. Find the function AddSendSubMenu. Go to the

Android问题集锦之四十九:Can't add XStream file dependency to Android Studio project

将xstream1.4.8 引入Android Strudio项目中,编译报错如下: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472) at

WAITEVENT: "library cache: mutex X" (文档 ID 727400.1)

WAITEVENT: "library cache: mutex X" (文档 ID 727400.1) 2014-01-19 09:56 2367人阅读 评论(0) 收藏 举报  分类: 网络资源_ORACLE_调优(108)  目录(?)[-] APPLIES TO PURPOSE SCOPE DETAILS Definition Individual Waits Systemwide Waits Wait Time Reducing Waits Wait times Known

How to Create an OCM Response file to Apply a Patch (文档 ID 966023.1)

How to Create an OCM Response file to Apply a Patch in Silent Mode - opatch silent (文档 ID 966023.1) APPLIES TO: Oracle Universal Installer - Version 10.2.0.1 to 11.2.0.4 [Release 10.2 to 11.2]Oracle Database - Enterprise Edition - Version 10.2.0.1 to

[翻译][Ruby教程]Nokogiri - 解析HTML/XML文档 / Parsing an HTML/XML Document

From a String From a File From the Internet Parse Options Encoding 原文: Parsing an HTML/XML Document 解析HTML/XML文档 从字符串读取 We’ve tried to make this easy on you. Really! We’re here to make your life easier. 1 html_doc = Nokogiri::HTML("<html><bo