将文档和元数据添加到文档库,无需创建 2 个版本

发布于 2024-08-13 10:10:28 字数 576 浏览 3 评论 0原文

我需要以编程方式将文件和元数据添加到文档库和事件处理程序中。我在异步“ItemAdded”和“ItemUpdated”事件中使用以下代码:

SPFile destFile = web.Files.Add(newUrl, newFile, true);

SPListItem destItem;
if (destFile.Item != null)
{
    destItem = destFile.Item;
}
else
{
    destItem = list.Items.Add(folderUrl, SPFileSystemObjectType.File);
}

foreach (DictionaryEntry property in properties)
{
    destItem.Properties[property.Key.ToString()] = property.Value;
}

destItem.Update();

但是,每次添加文件时,都会创建两个版本,一个在调用 Files.Add 方法时创建,一个在调用 SPListItem.Update 方法时创建叫。是否有另一种方法可以只创建一个版本?

提前致谢!

I have a requirement to programmatically add a file along with metadata to a document library and in an event handler. I am using the following code in the asynchronous “ItemAdded” and “ItemUpdated” events:

SPFile destFile = web.Files.Add(newUrl, newFile, true);

SPListItem destItem;
if (destFile.Item != null)
{
    destItem = destFile.Item;
}
else
{
    destItem = list.Items.Add(folderUrl, SPFileSystemObjectType.File);
}

foreach (DictionaryEntry property in properties)
{
    destItem.Properties[property.Key.ToString()] = property.Value;
}

destItem.Update();

However, each time a file is added, two versions are created, one when the Files.Add method is called and one when the SPListItem.Update method is called. Is there another way to do this where only one version will be created?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

银河中√捞星星 2024-08-20 10:10:28

使用

destItem.SystemUpdate( false );

代替 .Update() 以避免创建新版本。

Use

destItem.SystemUpdate( false );

in stead of .Update() to avoid creating a new version.

梦情居士 2024-08-20 10:10:28

Add() 方法有一个重写,它接受哈希表以将元数据与文件一起传递。这样就不需要调用 Update() 或 SystemUpdate() 方法。

The Add() method has an override which accepts a hashtable to pass metadata along with the file. This way there is no need to call Update() or SystemUpdate() methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文