SP Gugu: How to Programmatically change a list item's ContentType by WSS WebService?

Please, help! I can't find any information on MSDN under WSS3 webservices List.UpdateListItems topics

how to programmatically change a list item ContentTypeId

 

Calling SharePoint list service like: (adding a list item)

 

XmlElement elBatch = doc.CreateElement("Batch");

elBatch.SetAttribute("OnError", "Continue");

elBatch.SetAttribute("ListVersion", "2");

XmlElement el1 = doc.CreateElement("Method");

el1.SetAttribute("ID", "1");

el1.SetAttribute("Cmd", "New");

XmlElement field1 = doc.CreateElement("Field");

field1.SetAttribute("Name", "ID");

field1.InnerText = "New";

XmlElement field2 = doc.CreateElement("Field");

field2.SetAttribute("Name", "emp_no");

 XmlNode response = listService.UpdateListItems("Tasks", elBatch);

 



Answer this question

SP Gugu: How to Programmatically change a list item's ContentType by WSS WebService?

  • Pavel Makovec

    In order to update metadata you need to specify reference to the file that you want to update, here I found answer to my question:

    http://www.codecomments.com/message376403.html

    For me goal was to upload files to Sharepoint Programmatically and update metadata (Indexes, Column information) using Web Services.


  • Fyrus

    What is the corresponding way to set an SPListItem's ContentType directly using the WSS object model

  • Kamii47

    the desition was found:

    XmlElement field1 = doc.CreateElement("Field");

    field1.SetAttribute("Name", "ContentType");

    field1.InnerText = "theContentTypeName";


  • sdknewbie

    Hey there,

    I just came across this problem recently and have a solution just in case anyone stumbles upon this thread.

    // Grab the content type from the list so we can get the id
    SPContentType spctExampleContentType = splExampleList.ContentTypes["Example Content Type"];

    // Create the new item
    SPListItem spliNewItem = splExampleList.Items.Add();

    // Now set the content type id
    spliNewItem["ContentTypeId"] = spctExampleContentType.Id;
    spliNewItem.Update();

    // now we have access to set all the content type fields
    spliNewItem["Content Type Field 1"] = "Row";
    spliNewItem["Content Type Field 2"] = "Sham";
    spliNewItem["Content Type Field 3"] = "Bow";

    Pretty self explanatory, I'm not looking at my code right now but that is the general jist of it.

    Hope that helps!!
    Arnie



  • SP Gugu: How to Programmatically change a list item's ContentType by WSS WebService?