Wednesday, October 31, 2012

List ID for Event Handler

ListTemplate Element (List Template)

1200     Administrator tasks list
104     Announcements list
303     Blog Categories list
302     Blog Comments list
301     Blog Posts list
105     Contacts list
120     Custom grid for a list
118     Custom Workflow Process
130     Data Connection library
110     Data sources
108     Discussion board
101     Document library
106     Events list
150     Gantt Tasks list
100     Generic list
1100     Issue tracking
103     Links list
114     List template gallery
116     Master pages gallery
201     Meeting Agenda list
202     Meeting Attendees list
204     Meeting Decisions list
207     Meeting Objectives list
200     Meeting Series list
210     Meeting text box
211     Meeting Things To Bring list
212     Meeting Workspace Pages list
117     No-Code Workflows
2002     Personal document library
109     Picture library
300     Portal Sites list
2003     Private document library
111     Site template gallery
102     Survey
107     Tasks list
112     User Information list
113     Web Part gallery
119     Wiki Page library
140     Workflow History
115     XML Form library

Thursday, October 25, 2012

Account name from People picker



        We have person and group column in sharepoint.
We can specify what should be displayed in that field like Name,Account,Work-Email etc.
If u set it to Name for client purpose and you want Account name for other programming use you can use the following code.

string strName = GetUser(item, item.Fields["Discipline Approver"]).Name;


private SPUser GetUser(SPListItem item, SPField userField)
        {

            string currentValue = item[userField.Title].ToString();
            SPFieldUser field = (SPFieldUser)userField;
            SPFieldUserValue fieldValue = (SPFieldUserValue)field.GetFieldValue(currentValue);
            return fieldValue.User;

        }

Getting Sharepoint user profile values

private void GetUser(string name)
        {
           // string key = HttpContext.Current.Request.Params["id"].ToString();
           // int id = Convert.ToInt32(key);
            object user = null;

           
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(workflowProperties.SiteUrl))
                {
                     //SPUser user = SPContext.Current.Web.
                    SPServiceContext serverContext = SPServiceContext.GetContext(site);
                    UserProfileManager profileManager = new UserProfileManager(serverContext);
                   // SPUser spUser = site.RootWeb.Users.GetByID(id);
                    UserProfile profile = profileManager.GetUserProfile(name);

                    user = new
                    {
                        Account = profile["AccountName"].Value,
                        Title = profile["Title"].Value,
                        First = profile["FirstName"].Value,
                        Last = profile["LastName"].Value,
                        PreferredName = profile["PreferredName"].Value,
                        WorkPhone = profile["WorkPhone"].Value,
                        Fax = profile["Fax"].Value,
                        WorkEmail = profile["WorkEmail"].Value,
                        Office = profile["Office"].Value,
                        Manager = profile["Manager"].Value

                    };
                }
            });

           // JavaScriptSerializer ser = new JavaScriptSerializer();
           // context.Response.Write(ser.Serialize(user));
        }

Wednesday, October 17, 2012

SQL null CASE date trick

In Sql query if you want to check the date is null and select a date value you need to convert the date field to varchar.Otherwise the case statement will not run properly.
Eg.


CASE  WHEN a.RegDt='1900-01-01 00:00:00.000' THEN CAST(reg.LstUpd AS VARCHAR(32)) WHEN a.RegDt IS NULL  THEN CAST(REG.LstUpd AS VARCHAR(32)) ELSE a.RegDt END RegDt,