zaterdag 5 november 2011

Apply a SiteCollection ContentType on a List of a Site or SubSite


Apply a SiteCollection ContentType on a List using the SharePoint Webservice Lists.asmx .  

    private Boolean ApplyContentTypeOnList(string myUrl, string myList, string myContentTypeId)
    {
        Boolean retCode = true;
        SetStatus("Initialize webservice...");
        WS_Lists.Lists lists = new WS_Lists.Lists();
        if (chk_DefaultLoggin.Checked)
            lists.Credentials = System.Net.CredentialCache.DefaultCredentials;
        else
        {
            lists.PreAuthenticate = true;
            lists.Credentials = new System.Net.NetworkCredential(txt_UserID.Text, txt_PassWord.Text, txt_domain.Text);
        }
        lists.Url = myUrl + @"/_vti_bin/lists.asmx";
        try
        {
            this.SetStatus("Activate contenttypeID " + myContentTypeId +" on list " + myList);
            if (TMSI_Trace_On.Checked)
                this.traceThis("Apply contentType to list...");
            XmlNode myNode = lists.ApplyContentTypeToList(myUrl, myContentTypeId, myList);
            if (myNode.OuterXml == "")
            {
                // get ListId for URLLINK
                XmlNode listID = lists.GetList(myList);
                retCode = true;
            }
            else
            {
                retCode = false;
            }
        }
        catch (Exception exception1)
        {
            MessageBox.Show(exception1.Message, "Error on applying contenttype on list", MessageBoxButtons.OK);
            this.SetStatus("Error on applying contenttype on list");
            retCode = false;
        }
        finally
        {
            lists.Dispose();
        }
        return retCode;
    }

 

Geen opmerkingen:

Een reactie posten