Friday, July 8, 2011

Code to Create SharePoint views Programatically using SP WebService

public void CreateView(string strCategory)
{
WRCreateView.Views objCreateViews = new CreateViews.WRCreateView.Views();
objCreateViews.Url = "http://Sitename.net/sites/SiteCol/_vti_bin/views.asmx";

NetworkCredential netcred = new NetworkCredential("MyUserName", "MyPassword", "MyDomain");

objCreateViews.Credentials = netcred;

string strQuery = " " + strCategory + "";

string strRowLimit = "100";

string strViewFields = "";



System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

System.Xml.XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
System.Xml.XmlNode ndRowLimit = xmlDoc.CreateNode(XmlNodeType.Element, "RowLimit", "");
System.Xml.XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "");

ndQuery.InnerXml = strQuery;
ndRowLimit.InnerXml = strRowLimit;
ndViewFields.InnerXml = strViewFields;

XmlNode retNode = objCreateViews.AddView("{794D4A54-960D-2322-1234-B6A672927FB7}", strCategory, ndViewFields, ndQuery, ndRowLimit, "HTML", false);

//XmlNode xmln = objCreateViews.GetView("{794D4A54-960D-47FA-1234-B6A672927FB7}", "{44F80DED-1235-485B-9B47-3EB2FDD797B1}");
}

Wednesday, July 6, 2011

Programmatically start workflow

Steven Van de Craen's Blog - Programmatically start workflow: "Guid wfBaseId = new Guid('{6BE0ED92-BB12-4F8F-9687-E12DC927E4AD}');
SPSite site = ...;
SPWeb web = site.OpenWeb();
SPList list = web.Lists['listname'];
SPListItem item = list.Items[0];
SPWorkflowAssociation associationTemplate= list.WorkflowAssociations.GetAssociationByBaseID(wfBaseId);
site.WorkflowManager.StartWorkflow(item, associationTemplate, '');"