Add custom Workflow to a list

I have putted this in a feature receiver event.
The code is actually very straight forword.


public class MUACChangeEventReceiver : SPFeatureReceiver

SPList historyList = null;
SPList taskList = null;

public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = site.RootWeb;
SPList list = web.Lists[“Project site creation”];


//Get workflow by name
//SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.GetTemplateByName(Resources.Workflow.WorkflowDisplayName, CultureInfo.CurrentCulture);

Guid workflowTemplateGuid = Resources.Workflow.WorkflowId;
SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates[workflowTemplateGuid];

web.AllowUnsafeUpdates = true;

// Create workflow association
SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, Resources.Workflow.WorkflowDisplayName, taskList, historyList);

// Set workflow parameters
workflowAssociation.AllowManual = false;
workflowAssociation.AutoStartCreate = true;
workflowAssociation.AutoStartChange = false;

// Add workflow association to my list

// Enable workflow
workflowAssociation.Enabled = true;
web.AllowUnsafeUpdates = false;

private void TryGetHistoryList(SPWeb web)
historyList = web.Lists[“Workflow History”];
catch (ArgumentException exc)
// Create workflow history list
Guid listGuid = web.Lists.Add(“Workflow History”, “”, SPListTemplateType.WorkflowHistory);
historyList = web.Lists[listGuid];
historyList.Hidden = true;
private void TryGetTaskList(SPWeb web)
taskList = web.Lists[“Workflow Tasks”];
catch (ArgumentException exc)
// Create workflow tasks list
Guid listGuid = web.Lists.Add(“Workflow Tasks”, “”, SPListTemplateType.Tasks);
taskList = web.Lists[listGuid];
taskList.Hidden = true;

Deploy my WSP to a certain WebApplication and not Globally

Most often you want your customsolution to be deployed to only a specific webapplication but SharePoint won’t allow it.

It’s actually very easy to fix this by tricking SharePoint.


In your package manifest you add a safe control:

<Solution xmlns=””&gt;
<Assembly Location=”dll_name_of_your_solution.dll” DeploymentTarget=”GlobalAssemblyCache”>
             <SafeControl Assembly=”dll_name_of_your_solution,Version=,Culture=neutral, PublicKeyToken=****************” Namespace=”namespace_of_your_solution” TypeName=”*” />


Show Multiline Textbox value as Text

If you acces the value of a multiline field there will be HTML tags included, so… the way to get only the text is like this…

SPFieldMultiLineText field = (SPFieldMultiLineText)item.Fields[“FieldName”];
string text = field.GetFieldValueAsText(item[“FieldName”]);

I wrote an exstension method for this:

var text = item.RetrieveMultiLineValue(“fieldname”);


public static string RetrieveMultiLineValue(this SPListItem item, string fieldname)
string text = String.Empty;

if (item[fieldname] != null)
SPFieldMultiLineText field = (SPFieldMultiLineText)item.Fields[fieldname];
text = field.GetFieldValueAsText(item[fieldname]);

return text;

Voila, hope it helps, comments are welcome…

Jquery get current Sharepoint user

It is possible to get through JQuery the current user in SharePoint;

 var currentuser;

function checkCurrentUser() {
var context = SP.ClientContext.get_current();
var siteColl = context.get_site();
var web = siteColl.get_rootWeb();
this._currentUser = web.get_currentUser();
context.executeQueryAsync(Function.createDelegate(this, this.CheckUserSucceeded),
Function.createDelegate(this, this.CheckUserfailed));

function CheckUserSucceeded() {
currentuser =this._currentUser.get_loginName;

 function CheckUserfailed() {
log(‘retrieving user failed’);