开发者

Could not change the content type of a Document list item in a document library

I'm programatically changing the content type of a document in a document library. But document is getting added with the content type only.

Here is my coding:

SPFile ofile = oweb.GetFile(oweb.Url + '/' + oDocSet.Item.Url + '/' + refName);
ofile.Item["Content Typ开发者_C百科e"] = octype.Name;
ofile.Item["Content Type ID"] = octype.Id;
ofile.Item.Update();

when i traced the above coding the content type is getting changed when i assign them to the item but after I update the the item in the last line the content type of the item is getting set to the default content type.


Shouldn't it be:

SPFile ofile = oweb.GetFile(oweb.Url + '/' + oDocSet.Item.Url + '/' + refName); 
ofile.Item["ContentType"] = octype.Name; 
ofile.Item["ContentTypeId"] = octype.Id; 
ofile.Item.Update(); 

Note the lack of spaces in the field names

P.S.: Is the content type actually allowed in the library?


I had the same situation as described here. ContentType remains the same after save document in document library in custom form. Code provided above runs without exceptions and messages, but contenttype remains the same.

Problem solved with reverting back to default edit form, changing contenttype with it, and reassigning custom edit form in Sharepoint Designer again. Now contenttype changes work without problems.

Maybe it internal bug with sharepoint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜