Sharepoint SPFile.MoveTo()更改内容类型
使用SP2010。我得到了一个包含两个库的SPWeb(下面代码中的sentApplicationsList和sentApplicationsListXml)。在一个过程中,我需要将XML文件从第一个库移动到第二个库,因此我编写了以下代码:Sharepoint SPFile.MoveTo()更改内容类型,sharepoint,Sharepoint,使用SP2010。我得到了一个包含两个库的SPWeb(下面代码中的sentApplicationsList和sentApplicationsListXml)。在一个过程中,我需要将XML文件从第一个库移动到第二个库,因此我编写了以下代码: for (int i = 0; i < sentApplicationsList.Items.Count; i++) { SPFile file = sentApplicationsList.Items[i].File; if (file
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);
}
}
这没有任何区别
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();