Friday, May 22, 2015

Kerala Microsoft User Group Meeting - 23rd May 2015 (Saturday) - Kochi

Kerala Microsoft User Group Meeting is a free event organised by Kerala Microsoft User Group on 4th Saturday of every month.

Venue:

Orion India Systems Pvt Ltd, 2nd floor, Tejomaya - L&T Tech Park, Info park SEZ, Kakkanad, Cochin-682030
Agenda

09:30 - 09:45 Community updates
09:45 - 10:30 Kinect for Windows by Abhilash Ashok
10:30 - 11:15 Acquainting with Asp.net 5 and MVC 6 by Aswajith
11:15 - 11:30 Tea Break & Networking (15 min)
11:30 - 12:15 Secure web api with OAuth 2.0 OWIN OAuth middleware - Rifaj Aboobackar
12:15 - 01:00 Windows 10 by Yanesh Tyagi

Register

Sunday, May 17, 2015

Editing SharePoint List with Server Object Model

I am having a list called Employees which I have to edit using Visual Web Part.


private SPListItemCollection GetEmployee()
{
    SPSite site = new SPSite("http://toshiba-pc");
    SPWeb web = site.RootWeb;

    SPList lis = web.Lists["Employee"];
    SPQuery q = new SPQuery();
    q.Query = String.Format("<Where><Contains><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Contains></Where>", txtEmployee.Text);

    q.ViewFields = "<FieldRef Name='Employee_x0020_Location'/><FieldRef Name='Years_x0020_Of_x0020_Experience'/>";
     SPListItemCollection lic = lis.GetItems(q);
     return lic;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
      SPListItemCollection lic = GetEmployee();
      SPListItem li = lic[0];
      txtLocation.Text = li["Employee_x0020_Location"].ToString();
      int? intYears = Int32.Parse(li["Years_x0020_Of_x0020_Experience"].ToString());
      txtYearsOfExp.Text = intYears.ToString();
}

protected void btnEdit_Click(object sender, EventArgs e)
{
      SPListItemCollection lic = GetEmployee();
      SPListItem li = lic[0];
      li["Employee_x0020_Location"] = txtLocation.Text;
      li["Years_x0020_Of_x0020_Experience"] = txtYearsOfExp.Text;
      li.Update();
}


I am making use of CAML query to extract the details of the Employee and fill the details in the TextBox, which is later updated.