Monday, November 26, 2012

Filter SharePoint List by Workflow Status


Filter SharePoint List by Workflow Status

Often we need to filter a SharePoint list by  the status of a workflow.

This is rather simple and can be done in the same way as filtering any other field.

The only thing you need to know is that the status of the workflow is an integer, not a text.  So we can’t add a filter like ‘Workflow name’ IS EQUAL TO ‘In Progress’

The following list gives the integer values of each status.
This data can also be used within InfoPath to change the layout of the form depending on the status of the workflow.

A blog was written earlier how to do this:
List of Workflow statuses

  •      0 - Starting
  • 1 - Failed on Start
  • 2 - In Progress
  • 3 - Error Occurred
  • 4 - Canceled
  • 5 - Completed
  • 6 - Failed on Start (retrying)
  • 7 - Error Occurred (retrying
  • 15 - Canceled
  • 16 - Approved
  • 17 - Rejected

Saturday, October 27, 2012

Current User's Group Owner details Using Client object model

Current User's Group Owner details Using Client object model

Here i am trying to get the Group owners Email Id. Similar way we can get all details of the group owner.



                //COM For Current User
                ClientContext COMforCurrentUser = new ClientContext("http://htschdev01:8000/sites/hr");
                COMforCurrentUser.Load(COMforCurrentUser.Web.CurrentUser);
                COMforCurrentUser.ExecuteQuery();
                User CurrentUser=COMforCurrentUser.Web.CurrentUser;

                // Smtp Server Details
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                //COM For Owner Details
                ClientContext clientContext = new ClientContext("http://htschdev01:8000/sites/hr");
                Web web = clientContext.Web;
                GroupCollection groupColl = web.SiteGroups;
                clientContext.Load(groupColl,
                groups=>groups.Include(
                group=>group.Title,
                group=>group.Id));
                clientContext.ExecuteQuery();
                int Ownerid = 0;
                string OwnerMailID = "";
                foreach (Group siteGroup in groupColl)
                  {
                clientContext.Load(siteGroup);
                clientContext.ExecuteQuery();
                clientContext.Load(siteGroup.Users);
                clientContext.ExecuteQuery();
                UserCollection Tolalusers = siteGroup.Users;
                int count = siteGroup.Users.Count;
                string Groupname = siteGroup.Title;            
                User SiteOWner;
                foreach (User singleuser in Tolalusers)
                {
                    if (singleuser.LoginName == CurrentUser.LoginName)
                    {
                        clientContext.Load(siteGroup);
                        clientContext.ExecuteQuery();
                        clientContext.Load(siteGroup.Owner);
                        clientContext.ExecuteQuery();
                        Ownerid = siteGroup.Owner.Id;
                        string Ownername = siteGroup.Owner.LoginName;
                        foreach (User Owner in Tolalusers)
                        {
                            if (Owner.Id == Ownerid)
                            {
                                OwnerMailID = Owner.Email;
                                break;
                            }
                        }                                            
                        break;
                    }                  
                }              
            }
                mail.From = new MailAddress(OwnerMailID);               
                mail.To.Add(CurrentUser.Email);              
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from GMAIL";
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("XYZ@gmail.com", "Password");
                SmtpServer.EnableSsl = true;
                SmtpServer.Send(mail);
                MessageBox.Show("mail Send");

Tuesday, October 9, 2012

SharePoint RegistrationID For Sharepoint Contents


SharePoint RegistrationID For Sharepoint Contents

InvalidType = -1
GenericList = 100
DocumentLibrary = 101
Survey = 102
Links = 103
Announcements = 104
Contacts = 105
Events = 106
Tasks = 107
DiscussionBoard = 108
PictureLibrary = 109
DataSources = 110
WebTemplateCatalog = 111
UserInformation = 112
WebPartCatalog = 113
ListTemplateCatalog = 114
XMLForm = 115
MasterPageCatalog = 116
NoCodeWorkflows = 117
WorkflowProcess = 118
WebPageLibrary = 119
CustomGrid = 120
DataConnectionLibrary = 130
WorkflowHistory = 140
GanttTasks = 150
Meetings = 200
Agenda = 201
MeetingUser = 202
Decision = 204
MeetingObjective = 207
TextBox = 210
ThingsToBring = 211
HomePageLibrary = 212
Posts = 301
Comments = 302
Categories = 303
Pages = 850 
IssueTracking = 1100
AdminTasks = 1200


Referance:http://techtrainingnotes.blogspot.in/2008/01/sharepoint-registrationid-list-template.html

Wednesday, August 29, 2012

Inserting/Updating/Deleting the items in share point list by C# coding

Inserting/Updating/Deleting the items in  share point list by C# coding:


using (SPSite site = new SPSite("http://website url/" ))
02// Or SPContext.Current.Site.Url
03{
04    using (SPWeb Web = site.OpenWeb())
05    {
06            Web.AllowUnsafeUpdates = true;
07 
08            // Open List
09             SPList list = Web.Lists["MyList"];
10 
11            // Add new item in List
12             SPListItem item = list.Items.Add();
13             item["Title"] = "Test Title";
14             item["Description"] = "Test Description";
15             item.Update();
16 
17            // Get Item ID
18             listItemId = item.ID;
19 
20            // Update the List item by ID
21             SPListItem item = list.GetItemById(listItemId);
22             item["Description"] = "Update Description";
23             item.Update();
24 
25            // Delete item
26             SPListItem item = list.GetItemById(listItemId);
27             item.Delete();
28 
29            Web.AllowUnsafeUpdates = false;
30       }
31 }