C# 如何上载带有元数据的文档以避免重复版本控制? 我在SharePoint基金会2010中使用服务器对象模型将文档上传到文档库中。我正在使用以下代码 // Initialize instance of existing site collection using (SPSite site = new SPSite(siteUrl)) { //Initailize instance of exiting web site (for e.g. Team Site) using (SPWeb web = site.RootWeb) { //Get list with specified name in the existing web site SPList list = web.Lists[libraryName]; //Get the collection of folders in the existing web site String url = list.RootFolder.ServerRelativeUrl.ToString(); SPFolderCollection folders = web.GetFolder(url).SubFolders; //Add new folder in the exiting collection of folders SPFolder folder = folders.Add(folderName); //SPFolder folder = web.GetFolder(siteUrl + "/" + libraryName + "/" + folderName); //byte[] fileContents = System.IO.File.ReadAllBytes(@fileUrl); //Add file in the newly added folder with overwrite var overWrite = true; SPFile file = folder.Files.Add(saveFileWithName, fileContents, overWrite); //Get the list item of the newly added file SPListItem listItem = file.ListItemAllFields; //Assign values to the fields of newly added file listItem["User_x0020_Name"] = userName; listItem["Document_x0020_Type"] = documentType; listItem["Check_x0020_Type"] = checkType; //Update the list item with the newly added values to the fields listItem.Update(); //Get the unique id of the newly added list item documentGuid = listItem["UniqueId"].ToString(); } }

C# 如何上载带有元数据的文档以避免重复版本控制? 我在SharePoint基金会2010中使用服务器对象模型将文档上传到文档库中。我正在使用以下代码 // Initialize instance of existing site collection using (SPSite site = new SPSite(siteUrl)) { //Initailize instance of exiting web site (for e.g. Team Site) using (SPWeb web = site.RootWeb) { //Get list with specified name in the existing web site SPList list = web.Lists[libraryName]; //Get the collection of folders in the existing web site String url = list.RootFolder.ServerRelativeUrl.ToString(); SPFolderCollection folders = web.GetFolder(url).SubFolders; //Add new folder in the exiting collection of folders SPFolder folder = folders.Add(folderName); //SPFolder folder = web.GetFolder(siteUrl + "/" + libraryName + "/" + folderName); //byte[] fileContents = System.IO.File.ReadAllBytes(@fileUrl); //Add file in the newly added folder with overwrite var overWrite = true; SPFile file = folder.Files.Add(saveFileWithName, fileContents, overWrite); //Get the list item of the newly added file SPListItem listItem = file.ListItemAllFields; //Assign values to the fields of newly added file listItem["User_x0020_Name"] = userName; listItem["Document_x0020_Type"] = documentType; listItem["Check_x0020_Type"] = checkType; //Update the list item with the newly added values to the fields listItem.Update(); //Get the unique id of the newly added list item documentGuid = listItem["UniqueId"].ToString(); } },c#,sharepoint-2010,versioning,sharepoint-api,C#,Sharepoint 2010,Versioning,Sharepoint Api,上面的代码运行良好。我已在文档库上启用版本控制。当上述代码运行时,它会在文档库中创建两个版本。一个是用 SPFile file = folder.Files.Add(saveFileWithName, fileContents, overWrite); 另一个是将值添加到列User\u x0020\u Name,Document\u x0020\u Type和 检查\u x0020\u类型使用 listItem.Update(); 我只想在用户上传文档和添加元数据时创建一个版本。如何做到这一

上面的代码运行良好。我已在文档库上启用版本控制。当上述代码运行时,它会在文档库中创建两个版本。一个是用

SPFile file = folder.Files.Add(saveFileWithName, fileContents, overWrite);
另一个是将值添加到列
User\u x0020\u Name
Document\u x0020\u Type

检查\u x0020\u类型
使用

listItem.Update();

我只想在用户上传文档和添加元数据时创建一个版本。如何做到这一点?您能提供任何代码或链接来解决上述问题吗?

保持代码不变,只需将“listItem.Update();”替换为“listItem.SystemUpdate(false)”;“它将更新元数据,并且不会增加版本号