Showing posts with label sharepoint 2010. Show all posts
Showing posts with label sharepoint 2010. Show all posts

Tuesday, June 02, 2015

Removing multiple version of Workflow

This is simple workaround on removing multiple version of Workflow those associated with item.
Running the multiple versions of the workflow,long running instances of the workflow those are often leads to collapse the SharePoint's workflow  related timer jobs.

You have to follow always the best practices while you are publishing the SPD workflow such as stop / cancel the previous workflow or set no new instances on the previous workflow.

Here is code work around on removing the old instances of workflows from the SharePoint List item.

public void RemovePreviousWFInstances(SPListItem listItem)
        {
            using (var web = listItem.Web)
            {
                web.AllowUnsafeUpdates = true; 
                using (var site = web.Site)
                {
                   SPWorkflowManager manager = site.WorkflowManager;
                    foreach (SPWorkflow instance in manager.GetItemWorkflows(listItem))
                    {
                        if (instance.ParentAssociation.Name.Contains("Previous"))
                        {
                            manager.RemoveWorkflowFromListItem(instance);
                        }
                    }
                }
                web.AllowUnsafeUpdates = false;
            }
        }

Saturday, March 14, 2015

U2U Caml query builder for SharePoint 2010

If you are a experience SharePoint developer and developing the SharePoint technologies (MOSS 2007 and SharePoint 2010 ) over the years , you probably aware of the wonderful and productive tiny tool called "Caml Query Builder " developed by U2U.

But unfortunately,Caml Query builder for SharePoint 2010 has been removed from the U2U site without any reason or explanation.

Fortunately , I have my old data backup files and tools related to MOSS and SharePoint 2010 and found this tool.

If you are looking the same tool, please download it from here my Google Drive location

Now its time to roll out and move to SharePoint 2013 or Office 365. Or you wanted to leverage the Client Object Model or Webservice in SharePoint 2010,so  our CAML query builder tool must accommodates the latest interactive programs like WebService, JSON, Atom , REST API, Client Side Object Model, traditional webservices and so on.

So I was looking for updated "CAML Query Builder for SharePoint 2013" and found  the tool named "CamlDesigner 2013" very useful other than the tools available on the codeplex.

Salient Features of Caml Designer.

  • Drag and Drop the fields to create the CAML Query.
  • Generates the Client Object Model (REST,Managed .NET code , Webservice and PowerShell).
  • Supports the Office 365, SharePoint 2010 in the same tool.
  • Task bar notification on every task.
  • Still relevant to SharePoint 2010.


Download link : Caml Designer 




Tuesday, September 04, 2012

Adding SPUser programmatically

This few lines of code will be helpful for adding the SharePoint User or SharePoint Group through code. The string value for user id was given in excel format.My workaround was parsing the string in to token and identifying the user's windows log in id. Then inserting this value into people picker and updating the respective item. I have only one user to be added.If you have collection of users then you need to split the strings in comma delimiter and use the SPFieldUserValueCollection class.
 using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPUser userObj = SPContext.Current.Web.EnsureUser("Murugesan");
                    SPFieldUserValue userValue = new SPFieldUserValue(SPContext.Current.Web, userObj.LoginName);
                    SPList list = web.Lists["Project"];
                    SPListItem item = list.Items.Add();
                    item["Title"] = "Project-2";
                    item["Manager"] = userValue;
                    item.Update();
                }
            }

Monday, May 07, 2012

current user in sharepoint

Trimmed lines of code to get the currently logged in user details in SharePoint
 public SPUser GetCurrentUser()
        {
            var context = SPContext.Current;
            SPWeb web = context.Web;
            return web.CurrentUser;
        }

After you getting the SPUser object you can retrieve the login name,email,first name and last name of this user.

Wednesday, August 17, 2011

Looping the people picker values

Recently I encountered the strange error while retrieving the all user from the
People picker control using SPQuery.
My datatable comes with Site user id and Name.As I wanted to assign these user to a
specific task in workflow.
while using these first user comes without site user id and the remaining were perfect as i expected.
I should admit,I tried many times but could not figure it out for my first user comes along with site id.Finally I made it to work.

Firstly queried the all user from the people picker control with certain condition using CAML.
 private string GetApproverList()
        {
            using (SPWeb web = workflowProperties.Web)
            {
                string appList = "";
                SPList docApproverList = web.Lists["DocApprovers"];
                
                string DocType = workflowProperties.Item["DocumentType"].ToString();               
                SPQuery q = new SPQuery();
                
                //q.Query = q.Query = "" + DocType + "";
                q.Query = "" + DocType + "";
                DataTable dt = docApproverList.GetItems(q).GetDataTable();
                foreach (DataRow row in dt.Rows)
                {
                    appList = appList + row["Approvers"].ToString()+",";
                }
                return appList.TrimEnd(',');
            }
        }


Secondly split this string into array by passing the comma sperator and '#' separator.
 string DocListUser = GetApproverList();
            string[] uids = DocListUser.Split(';', '#');
            for (int a = 0; a < uids.Length; a++)
            {
                if (uids[a].ToString() != "" && !CheckNumber(uids[a].ToString()))
                {
                    uidsList.Add(uids[a]);
                }

            }
Now I have final string array which comes with "",user id and display name.
public bool CheckNumber(string value)
        {

            int number1;
            return int.TryParse(value, out number1);
        }
I used array list to add each items in above string.Then I omit the "" string and numbers in the array.
 foreach (var userList in uidsList)
            {
                SPUser user = SPContext.Current.Web.EnsureUser(userList.ToString());
                assignees.Add(user.LoginName);
            }

Monday, January 17, 2011

SPListItem updating programmatically

After multiple attempts of opening the site using SPSite class,I could not make it happen.But searching of these topics i learned many tips and idea to resolve my task.
My requirement was having on webpart there I must create the Form to be filled by end user.These will be inserted into SharePoint List.
In Visual webpart I used the below code
 SPSite site = SPContext.Current.Site;
               SPWeb web = site.OpenWeb();
                SPList myList = web.Lists["List OF Employee"];
                SPListItem Item = myList.Items.Add();
                Item["Title"] = TextBox1.Text;
                Item["Name"] = TextBox2.Text;
                Item.Update();