SPFile.MoveTo()更改内容类型

时间:2013-08-23 09:06:12

标签: sharepoint

使用SP2010。我在下面的代码中得到了一个带有两个库的SPWeb( sentApplicationsList sentApplicationsListXml )。在一个过程中,我需要将XML文件从第一个库移动到第二个库,所以我写了这个:

for (int i = 0; i < sentApplicationsList.Items.Count; i++)
{
    SPFile file = sentApplicationsList.Items[i].File;
    if (file != null && file.Name.EndsWith(".xml"))
    {
        string newUrl = sentApplicationsListXml.RootFolder.Url + "/" + file.Name;
        file.MoveTo(newUrl, true);
    }
}

当项目在sentApplicationsListXml中出现时,它具有 Document 内容类型,而不是我的自定义内容类型。为什么SPFile.MoveTo()会更改内容类型?我的内容类型在两个库中都已激活。

为了尝试在MoveTo()之后更改内容类型,我添加了几行:

string newUrl = sentApplicationsListXml.RootFolder.Url + "/" + file.Name;
SPContentType contentType = file.Item.ContentType;
file.MoveTo(newUrl, true);
SPFile movedFile = web.GetFile(newUrl);
movedFile.Item[SPBuiltInFieldId.ContentType] = contentType;
movedFile.Item[SPBuiltInFieldId.ContentTypeId] = contentType.Id;
movedFile.Item.SystemUpdate();

这没有任何区别。

0 个答案:

没有答案
相关问题