Add a file to a Document Library and update metadata properties in a single method添加文档的方法
2014-11-04 15:45
393 查看
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; } } }); }
相关文章推荐
- Mysql官方文档中争对安全添加列的处理方法。Mysql Add a Column to a table if not exists
- Uploading files to the SharePoint Document Library and updating any metadata columns
- Android开发中出现in the gradle.properties file, sets the maximum Java heap size to 1024m的解决方法
- Use Matadata file to add attributes for properties in Ria service
- Using GDI+ in a Single Document MFC Project to Rotate, Zoom, and Constraint an Image
- [Drupal] How to add the js file and js code block in Drupal
- 14. 59. 6.JTable添加逻辑值的方法 Add logic to get value method
- 对Document library中修改文档的Author之添加checbox在list(二)
- 对Document library中修改文档的Author之利用Feature添加新的Menu (初步方案)
- 对Document library中修改文档的Author之利用Feature添加新的Menu (一)
- ASP.NET 2.0: Add build-in paging feature to repeater/为repeater添加内置分页功能
- Using Imagecache and CCK Imagefield to Add an Image in Drupal
- Using MERGE in SQL Server to insert, update and delete at the same time
- How to solve problem caused when the CRT library and MFC libraries are linked in the wrong order
- how to compile and link static/dynamic library in linux
- Configuration of DLL usage in VS2005--how to add additionl lib and head file
- [Tips] How to Add New field into Shapefile attribute table in ArcGIS ?
- If you whant to download SIS, JAR and JAD file from WAP you have to upload file (in the same catalog) with this: [小糊涂的灵感]
- How to invoke the method of managed bean and render view in JSF when we are outside the lifecycle of JSF
- Install and configure Gnupg & Use Gnupg to encrypt file in PHP