Showing posts with label Server Object Model. Show all posts
Showing posts with label Server Object Model. Show all posts

Wednesday, March 2, 2016

How to dynamically Building HTML Table with SharePoint List

NameSapce:
Using System.Text

Coding:
strtxt append any kind text numerics.

public void bindata()
{
try{

SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        StringBuilder strtxt = new StringBuilder();
                        strtxt.Append("<table width='100%'>");
                        strtxt.Append("<tr>");
                        strtxt.Append("<td  bgcolor='#add8e6'>");
                        
                        strtxt.Append(" Name");
                       
                        strtxt.Append("</td>");
                        strtxt.Append("</tr>");
                        SPWeb currentWeb = SPContext.Current.Web;
                        SPList lstemp = currentWeb.Lists["Employee"];
                        SPListItemCollection myColl = lstemp.Items;
                        if (myColl.Count > 0)
                        {
                            foreach (SPListItem item in myColl)
                            {
                                string strTitle = string.Empty;
                                strTitle = item.Title.ToString();
                                strtxt.Append("<tr>");
                                strtxt.Append("<td>");
                                strtxt.Append(strTitle);
                                strtxt.Append("</td>");
                                strtxt.Append("</tr>");
                            }
                        }
                        strtxt.Append("</tr>");
                        writer.Write(strtxt);
                    });
                }
                catch (Exception ex)
                {
                    writer.Write(ex.ToString());
                }
            }
}

How to Insert New Item Into SharePoint List Programmatically

using (SPSite spSite = new SPSite(strSiteUrl, token))
{
spSite.AllowUnsafeUpdates = true;
using (SPWeb spWeb = spSite.OpenWeb())
{


SPList spList = spWeb.Lists["Enquiry"];

SPListItem spListItem = spList.Items.Add();

spListItem["Title"] = "Peak";
spListItem["Location"] = "India";


spWeb.AllowUnsafeUpdates = true;
 spListItem.Update();
}

}

Friday, February 12, 2016

When we get retrive People or Group field returning semicolon hash then Name

1;#Deepak Kumar


Get User name:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupValue;


Get User ID:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupId;

Using Split fuction:

properties.ListItem["Staff Member"].ToString();

You are going to be returned their userID and username, so it will always be returned separated by ;#.



properties.ListItem["Staff Member"].ToString().split(";#")[1];

Tuesday, December 15, 2015

How to update hyperlink filed value in SharePoint List using Server Object Model ?



SPListItem oiitem= oList.GetItemById(itemidvalue);
SPFieldUrlValue furl= new SPFieldUrlValue();

furl.URL = "peakfinders.blogspot.in";

furl.Description = "Peak Finders";

oiitem["SiteURL"] = furl ;

oiitem.update();