Showing posts with label Feature. Show all posts
Showing posts with label Feature. Show all posts

Thursday, August 13, 2009

Adding a Description for SharePoint Designer Workflow

I have seen this question in many places “How to add description for a SharePoint Designer Workflow?” I had the same requirement; googling does not give me the result to achieve the same :-). See the image of a sample workflow generated by SharePoint Designer.



Unfortunately, SharePoint Designer does not provide an option for adding workflow description. I have looked at the files which is generated by designer, but unsuccessful. See the files generated by a SharePoint Designer Workflow



The finally I decided to write a piece of code using SharePoint Object Model to achieve the same.

private void AddWorkflowDescription(string siteURL, string listName, string workflowName, string workflowDesc)
{
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
SPList _linksList = web.Lists[listName];

foreach (SPWorkflowAssociation _wfAssoc in _linksList.WorkflowAssociations)
{
if (_wfAssoc.Name.ToLower().Equals(workflowName))
{
_wfAssoc.Description = workflowDesc;
_linksList.UpdateWorkflowAssociation(_wfAssoc);
break;
}
}
}
}
}


Feature Activated Code

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
string _siteURL = "http://mossserver:4545/sites/Demo/";
string _listName = "Links";
string _workflowName = "workflow 1";
string _workflowDesc = "Workflow Descriptiopn updated by code";
AddWorkflowDescription(_siteURL, _listName, _workflowName, _workflowDesc);
}


I have added this code in my “Feature Activated” event. The following image shows a SharePoint designer workflow with description which is generated by the above code.



Note:
If you just want to run this code only once then create a Console Application / Windows application to execute the above code.

Wednesday, July 29, 2009

SharePoint Custom Page Layout – Web Parts getting added twice

I have used SharePoint Designer to create a custom page layout and added few custom web parts (drag-drop using SPD).

The Page Layout has been deployed using a Feature. After deployment, The Page Layout has web parts as expected and the issue is, when a page is created using the custom Page Layout, each web part is added twice.

I have tried different approaches to remove the web parts unsuccessfully. Finally removed all web parts (which I have added using SharePoint Designer) and used “
AllUsersWebPart” element to add custom web parts in Feature. It worked like a charm!