0

I just used follwing script to change content type files in a document library but it seems that it works only on old files. the files must be created some time before you run the script. It is even not possible to change the content type by using GUI even I am Farm Admin.

I think you can change content type if you have files in the list have created earlier than 48 hours or something. Here is the script, no errors or problem with the script

    $listItem.File.CheckOut()
    $listItem["ContentTypeId"] = $MyCTID
    $listItem.Update()
    $listItem.File.CheckIn("Content type changed to " + $MyCT.Name, 1)

I have tested with/without SystemUpdate() and with/without checkout checkin.

1
  • Are you asking how you change the content type for new files added to the document library? May 10 '12 at 14:09
1

I just tried it myself and it worked fine. Make sure if you have the content type configured on the document library beforehand.

3
  • Hi, Thanks, It is strange, because it changes som files but not all. what do you mean exactly "content type configured" because I usualy get the content type from the list: $MyCT = myList.ContentTypes["myContentType"] do you tried to add a new document to the list and after that change the content type of the document? first when you add the documenet must have default contenet type of the list and then try to change the content type to another which was added to the list.
    – Medes
    May 11 '12 at 11:36
  • When I say content type configured I mean the list must have the content type added before running the code. And yes I tried the same steps you mentioned.
    – Emon
    May 12 '12 at 13:09
  • Sometimes it is impossible change the content type of the document even by using GUI. so it must be something which prevents it.
    – Medes
    May 13 '12 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.