天道酬勤,学无止境

sharepoint 2010 spwe

2013 SharePoint复习 -- 新建Item / Folder / File

1. SPList.AddItem() a. 如果不带参数,AddItem()用于向List中添加item,不能用于向文档库中添加文件; 但SPList.AddItem("","")和SPList.AddItem("","","")可以用来添加folder,但URL必须使用Server-Relative url; SPListItem newFile = library.AddItem("/sites/TestSite/TestLibrary/TempFolder", SPFileSystemObjectType.Folder); newFile["Name"] = "ttt"; newFile.Update();2. SPFileCollection.Add() a. 用于向文档库中添加文件时使用,使用的是web-relative url; SPFile file = web.GetFile("TestLibrary/TempFolder/TempSubFolder/template.xlsx"); SPFileCollection files = web.GetFolder("TempFolder/TempSubFolder").Files; SPFile newFile = files.Add("testFile.txt", file.OpenBinary(), true)

2021-05-11 16:22:13    分类:博客    sharepoint 2010 spwe   复习