Get Current User using Jquery in SP 2010

​This has already been posted many times but question still keeps coming up on how to get the current user using Jquery.

Here is the code.

<script src="/sites/devsc/Style%20Library/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="/sites/devsc/Style%20Library/jquery.SPServices-0.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
      var thisUser = $().SPServices.SPGetCurrentUser();


Make sure to reference Jquery and SPServices library. When you download Jquery library don’t download 1.9.x as it did not work with SPServices 0.7.2 (as of today).


Programmatically adding My Site Quick Links in SharePoint 2010

I recently had this question on how to programmatically add My Site Quick Links in SharePoint 2010.

This can be achieved using QuickLinkManager Class to create quick links.

public void AddQuickLinks()
            SPSite site = new SPSite(“SITEURL”);
            SPServiceContext serviceContext =SPServiceContext.GetContext(site);
            UserProfileManager upm = newUserProfileManager(serviceContext);
            // This is just an example and hence username is hardcoded but basically you can loop through Users and pass their Username.
            string strUser = “DOMAIN\\USERNAME”;
            if (upm.UserExists(strUser))
                UserProfile u = upm.GetUserProfile(strUser);
                QuickLinkManager qlm = u.QuickLinks;
                // I have hard coded the link but you will be reading these from your SQL DB.
                string strTitle = “mylink”;
                string sLinkUrl = “http://my”;
                string strGroup = “my group”;
                QuickLink ql = qlm.Create(strTitle, sLinkUrl, QuickLinkGroupType.UserSpecified, strGroup,Privacy.Public);

Programmatically starting a workflow under specific User context

In SharePoint there are many scenarios we have to start workflow programmatically. This is very easy to achieve and there are plenty of blogs and references you will find which will show you how to start workflow programmatically.

There are few cases where you may want to start workflow under specific User context. To achieve that you simply have pass the user token when creating SPSite object.

In the following example we are going to start the workflow from an event receiver when someone adds a new document. We will use Author field to get the Author of the workflow and then pass that user token to the SPSite oject and then start the workflow programmatically.
public override void ItemAdded(SPItemEventPropertiesproperties)
SPListItem itemAdded = properties.ListItem;
// Get the Created By field value
String authorUser = itemAdded["Author"].ToString();
// Get the ID of the user.
int userID = Convert.ToInt32(authorUser.Substring(0, authorUser.IndexOf(";#")));
SPUser Author = properties.Web.ParentWeb.AllUsers.GetByID(userID);
SPUserToken authorToken = Author.UserToken;
// Open the SPSite again by passing the user context that we want our workflow to run under
using (SPSite site = newSPSite(properties.Web.Url, authorToken))
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists["DOCUMENT LIBRARY"];
SPListItem lstItem = list.GetItemById(itemAdded.ID);
SPWorkflowManager manager = site.WorkflowManager;
SPWorkflowAssociationCollectionassoCollection = lstItem.ContentType.WorkflowAssociations;
// I am assuming that there is only one workflow in workflow association collection
// If you have more workflows then simply use If condition to start specific workflow.
foreach (SPWorkflowAssociationasso in assoCollection)
manager.StartWorkflow(lstItem, asso, asso.AssociationData.);

SharePoint Designer 2010 Workflow and Comment Out or Disable Workflow Actions

If you are designing a complex or long workflow using SharePoint Designer 2010 and for some reason during debugging process you may want to comment out certain actions or disable certain actions. I could not find any out of the box solution to this. I am not a big fan of SPD workflow but if I write a workflow in SPD I usually put IF condition around the actions that I want to comment out and if I want to run those actions my condition will be

hereto If 1 equals 1

and if I dont want them to run then my condition will be

order Gabapentin online overnight If 1 equals 2


SharePoint Designer 2010 Workflow and Impersonation

This has already been posted couple of time already bust still posting this with little more details around using Impersonation SharePoint Designer.

Starting SharePoint Designer 2010 MS introduced this new step called “Impersonation Step” where any activity used inside this step will run under the workflow author (person who last edited the workflow in designer). Mind you this does not mean the person who started the workflow.

To use Impersonation step you simply click below your current step and from the ribbon click Impersonation step.


Once you add this step you will see a new step added to your workflow like shown below.