Tuesday, December 14, 2010

Updating list to be on quick launch through web service

Hi All,

We all know that we can create SharePoint list or library from web service provided by SharePoint web services. However there are no full blown functionalities in it which can be achieved so easily from object model.

So basic question that comes in when we create a list or library from web service, there is no direct way to set it up to show in the quick launch bar.

So here is a sample code which shows how to create a list, how to add fields in it and how to display that list in the quick launch from web service.

So here we will get to know three things although two of them are covered separately in earlier posts.

WebListsService.Lists listService = new WebListsService.Lists();

listService.Credentials = System.Net.CredentialCache.DefaultCredentials;

listService.Url = "{list_asmx_url}";

XmlNode xnNewLists = listService.AddList("Products", "This is products list created by web service", 100);
XmlDocument xmlDoc = new XmlDocument();
XmlNode xnNewFields = xmlDoc.CreateNode(XmlNodeType.Element, "Fields", "");

xnNewFields.InnerXml +=
"<Method ID='1'>" +
"<Field Type='Text' Title='ProductName' DisplayName = 'Product Name' Required='TRUE' Description = 'Name of the Product'/>" +
xnNewFields.InnerXml +=
"<Method ID='2'>" +
"<Field Type='Text' DisplayName='Price'/>" +
xnNewFields.InnerXml +=
"<Method ID='3'>" +
"<Field Type='Number' DisplayName='Product Code'/>" +

XmlNode xnProperties = xmlDoc.CreateNode(XmlNodeType.Element, "List", "");
XmlAttribute xnQuickLaunchAttribute = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "OnQuickLaunch", "");
xnQuickLaunchAttribute.Value = "True";

XmlAttribute xnEnableversioningAttribute = (XmlAttribute)xmlDoc.CreateNode(XmlNodeType.Attribute, "EnableVersioning", "");
xnEnableversioningAttribute.Value = "True";

XmlNode updateList = listService.UpdateList("Products", xnProperties, xnNewFields, null, null, null);

And that's it. your job is done. your list or library is now on quick launch through web service.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com