ProcessBatchUpdate不更新文档库
本文关键字:文档 更新 ProcessBatchUpdate | 更新日期: 2023-09-27 18:14:02
我有一个正在开发的应用程序,它使用Event接收器将元数据传播到文档库。我正在尝试使用SPWeb。ProcessBatchUpdate将元数据复制回来。我的代码是这样的:
public string UpdateClosingBookDocuments(SPWeb web, SPList closingBooksDocuments, SPListItemCollection items, SPListItem sourceListItem)
{
StringBuilder batchDataStringBuilder = new StringBuilder("<?xml version='"1.0'" encoding='"UTF-8'"?><ows:Batch OnError='"Return'">");
//string command = generateCommand(closingBooksDocuments.ID, sourceListItem, "urn:schemas-microsoft-com:office:office#");
string command = generateCommand(closingBooksDocuments.ID, sourceListItem, null);
foreach (SPListItem item in items)
{
batchDataStringBuilder.AppendFormat(command, item["ID"]);
}
batchDataStringBuilder.Append("</ows:Batch>");
web.AllowUnsafeUpdates = true;
return web.ProcessBatchData(batchDataStringBuilder.ToString());
}
private string generateCommand(Guid ID, SPListItem sourceListItem, string varNameSpace)
{
StringBuilder commandBuilder = new StringBuilder("<Method ID='"{0}'"><SetList>");
commandBuilder.Append(ID.ToString());
commandBuilder.Append("</SetList>");
commandBuilder.Append("<SetVar Name='"Cmd'">Save</SetVar>");
commandBuilder.Append("<SetVar Name='"ID'">{0}</SetVar>");
if (null != sourceListItem["Book Type"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsBookType'">{0}</SetVar>", sourceListItem["Book Type"], varNameSpace);
}
if (null != sourceListItem["Matter Number"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsMatterNumber'">{0}</SetVar>", sourceListItem["Matter Number"], varNameSpace);
}
if (null != sourceListItem["Matter Name"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsMatterName'">{0}</SetVar>", sourceListItem["Matter Name"], varNameSpace);
}
if (null != sourceListItem["Closing Date"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsClosingDate'">{0}</SetVar>", sourceListItem["Closing Date"], varNameSpace);
}
if (null != sourceListItem["Disposition Date"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsDispositionDate'">{0}</SetVar>", sourceListItem["Disposition Date"], varNameSpace);
}
if (null != sourceListItem["Principal Williams Party"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsPrincipalParty'">{0}</SetVar>", sourceListItem["Principal Williams Party"], varNameSpace);
}
if (null != sourceListItem["Principal Counter Party"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsCounterParty'">{0}</SetVar>", sourceListItem["Principal Counter Party"], varNameSpace);
}
if (null != sourceListItem["Other Parties"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsOtherParties'">{0}</SetVar>", sourceListItem["Other Parties"], varNameSpace);
}
if (null != sourceListItem["Asset Name"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsAssetName'">{0}</SetVar>", sourceListItem["Asset Name"], varNameSpace);
}
if (null != sourceListItem["Deal Team"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsDealTeam'">{0}</SetVar>", sourceListItem["Deal Team"], varNameSpace);
}
if (null != sourceListItem["Legal Department SIC"])
{
commandBuilder.AppendFormat("<SetVar Name='"{1}WilliamsLegalDeptSIC'">{0}</SetVar>", sourceListItem["Legal Department SIC"], varNameSpace);
}
commandBuilder.Append("</Method>");
return commandBuilder.ToString();
}
}
它生成一个CAML片段,看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<ows:Batch OnError="Return">
<Method ID="1">
<SetList>c5a3d89c-3f2b-409b-9743-1417db707586</SetList>
<SetVar Name="Cmd">Save</SetVar>
<SetVar Name="ID">1</SetVar>
<SetVar Name="WilliamsBookType">Financings</SetVar>
<SetVar Name="WilliamsMatterNumber">62626</SetVar>
<SetVar Name="WilliamsMatterName">Debug Matter</SetVar>
</Method>
<Method ID="2">
<SetList>c5a3d89c-3f2b-409b-9743-1417db707586</SetList>
<SetVar Name="Cmd">Save</SetVar>
<SetVar Name="ID">2</SetVar>
<SetVar Name="WilliamsBookType">Financings</SetVar>
<SetVar Name="WilliamsMatterNumber">62626</SetVar>
<SetVar Name="WilliamsMatterName">Debug Matter</SetVar>
</Method>
</ows:Batch>
结果如下:
<Results><Result ID='"1'" Code='"0'">'r'n</Result>'n<Result ID='"2'" Code='"0'">'r'n</Result>'n</Results>
文档库中没有任何更新!怎么了?
http://www.dmcinfo.com/Latest-Thinking/Blog/articleType/ArticleView/articleId/8471/Using-SPWebProcessBatchData-to-Update-Document-Library-Properties.aspx摘要:当在文档库上运行ProcessBatchUpdate时,您需要包含{0}并在每个项中传递文件的服务器相对url。使用SPListItem.File.ServerRelativeUrl或SPListItem.Folder.ServerRelativeUrl