Another interesting case...
Programmatically upload an xml file (extension should be .xml) to SharePoint document library. As soon as you upload it, try to change the Title field of the item.
So here is the code:
// We upload the file to SharePoint
SPFile file = Web.Files.Add(itemUrl, buff, true);
Web.Update();
string newTitle = "Sample Title";
SPListItem destItem = file.Item;
destItem.File.CheckOut();
// Try to change the title
destItem["Title"] = newTitle;
destItem.UpdateOverwriteVersion();
destItem.File.CheckIn(string.Empty,
SPCheckinType.MinorCheckIn);
For any non-xml extension files it works, but for xml files the Title doesn't change - it remains the same as the original name of the uploaded file. If you try doing this with another field of the item, it would work.
I came up with the following workaround:
SPFile file = Web.Files.Add(itemUrl, buff, true);
Web.Update();
string newTitle = "Sample Title";
SPListItem destItem = file.Item;
destItem.File.CheckOut();
destItem["Title"] = newTitle;
destItem.UpdateOverwriteVersion();
// Work-around start
destItem["Title"] = newTitle;
destItem.Update();
// Workaround end
destItem.File.CheckIn(string.Empty, SPCheckinType.MinorCheckIn);
Anyone has clue what's going on? Original MSDN forum thread is here.
No comments:
Post a Comment