Plug-in code for SharePoint List creation

Like most of you know, Microsoft has created a demo VPC which you can download from partnersource. On this demo there are some interesting features. For instance, if you do create an account, then automatically a sharepoint folder is created and linked to the account. This has been done by using a plugin. The plug-in code has been added below. Of course you will need to change some things related to URLs and credentials, but this should get you started very quickly.


public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = (DynamicEntity) context.InputParameters.Properties["Target"];
string listName = entity["name"].ToString();
string g = context.OutputParameters.Properties["id"].ToString();
int templateID = 0x65;
Lists lists = new Lists();
lists.Url = "http://sharepoint/crmdocs/_vti_bin/Lists.asmx";
lists.Credentials = new NetworkCredential("administrator", "pass@word1", "contoso");
string str3 = lists.AddList(listName, listName + " Document Library", templateID).InnerXml.ToString();
DynamicEntity entity2 = new DynamicEntity();
entity2.Name = EntityName.account.ToString();
entity2["accountid"] = new Key(new Guid(g));
entity2["new_sharepointdocumentlibraryurl"] = "http://sharepoint/crmdocs/" + listName + "/Forms/AllItems.aspx";
context.CreateCrmService(true).Update(entity2);
}

No comments: