Sunday, November 28, 2010

About SharePoint

Share Point Introduction

Microsoft SharePoint Server (formerly known as Microsoft Office SharePoint Server) is a Microsoft proprietary software product build on the ASP.NET framework. SharePoint Server works with Microsoft IIS web server to produce sites intended for collaboration, file sharing, social networking and web publishing. SharePoint server farms can host web sites, portals, intranets, extranets, Internets; web content management systems, search engine, wikis, blogs, social networking, business intelligence, workflow as well as providing a framework for web application development.
SharePoint only runs on Microsoft Windows Server and requires the ASP.NET framework be installed. Current SharePoint 2010 was developed on ASP.NET 3.5 and is not compatible with ASP.NET 4. SharePoint also requires a database. SharePoint only works with Microsoft SQL Server or Microsoft SQL Server Express database.

Microsoft has defined the following key capacities for SharePoint 2010. Most of these are supported with the 2007 product unless indicated.

SharePoint 2010 Sites provides single infrastructure for all your business Web sites. SharePoint can be used to create sites from Internet to extranet sites through Intranet Portals, blogs, wikis, to team sites.

SharePoint 2010 Communities provide collaboration tools including a social community and collaborative creation of content. Key community tools include collaborative document management, discussion forums, blogs, wikis and a Social Networking solution called MySites.

SharePoint 2010 introduced Composites. Composites offer tools and components for creating and distributing "do-it-yourself" business solutions. Composites allow users to create solutions to business problems in graphic tools without having to create or compile code by hand. Composites will allow users to share their solutions with other users on the SharePoint Server farm.
Composites aim to allow users to enable users to create solutions to business problems with familiar tools or in a web browser. The goal is that no code will be required to make the solution. These solutions can then be distributed through an enterprise via SharePoint Server. Composites will allow Enterprise web distribution of Microsoft Office products like Visio, Excel, and Access databases. There is also the ability to use the web page to build custom web parts. SharePoint Designer also offers users the ability to create solutions without code.

SharePoint provides a Web Content Management platform for publishing web sites. It also provides a Document Management solution for collaborative document production.

SharePoint 2010 can be used to surface business information in databases, reports, business applications and other applications.

SharePoint comes with its own Enterprise search. SharePoint can also be implemented using for improved search. The new SharePoint search now supports query syntax allowing search strings to contain OR, AND and NOT to refine the logic of the search. This now provides Boolean search which was not supported in earlier versions. SharePoint Server 2010 now also supports wild card search using the '*' character. SharePoint Server 2010 Search platform provides search of community data held in SharePoint MySites. Search is now designed to provide tacit knowledge about users and authors as well as semantic meaning. SharePoint now provides FAST search technology as a potential added feature. FAST provides vastly most sophisticated search and can index up to a half billion documents.

Sunday, November 14, 2010

Get details from announcment list

using (site = SPContext.Current.Site)
using (web = SPContext.Current.Web)
myLib = web.Lists["Announcements"];
libItems = myLib.Items;
if (libItems.Count == 0)
lblMsg.Text = "There are no items to show in this \"" + myLib.ToString() + "\"";
lblMsg.Text = "";
libItems = myLib.Items;
DataTable dt = new DataTable();
dt.Columns.Add("ImageURL", typeof(string));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Body", typeof(string));
dt.Columns.Add("Height", typeof(string));
dt.Columns.Add("Width", typeof(string));
dt.Columns.Add("URL", typeof(string));
dt.Columns.Add("UName", typeof(string));
dt.Columns.Add("Time", typeof(string));
dt.Columns.Add("AddNew", typeof(string));
if (libItems.Fields.ContainsField("Body") == true && libItems.Fields.ContainsField("ImageURL") == true)
foreach (SPListItem item in libItems)
string imageURL = item["ImageURL"].ToString();
string title = item["Title"].ToString();
string body = item["Body"].ToString();
string listURL = myLib.DefaultDisplayFormUrl +"?ID="+item.ID;
string userName = item["Author"].ToString();
string[] uName = userName.Split('#');
string Time = item["Created"].ToString();
string addNew = item.Web.Url + myLib.DefaultNewFormUrl;
int length = body.Length;
if (length >= 200)
body = body.Substring(0, 200) + "...";
dt.Rows.Add(imageURL, title, body, strPtyImgHeight, strPtyImgWidth, listURL,uName[1], Time, addNew);
dtlGetAnnouncement.DataSource = dt;
hlnkAddnew.NavigateUrl = web.Url + myLib.DefaultNewFormUrl; ;
else if (libItems.Fields.ContainsField("Body") == false)
lblMsg.Text = "There are no Column Name 'Body' in your \"" + myLib.ToString() + "\"";
else if (libItems.Fields.ContainsField("ImageURL") == false)
lblMsg.Text = "There are no Column Name 'ImageURL' in your \"" + myLib.ToString() + "\"";

Monday, November 1, 2010

SharePoint Basic Source Codes

Get Discussion names and their item count

SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPListCollection disccontrol = web.Lists;
DataTable dt = new DataTable();
dt.Columns.Add("DiscName", typeof(string));
dt.Columns.Add("DiscCount", typeof(string));
var tot = 0;
foreach (SPList dlist in disccontrol)
if (dlist.BaseTemplate == SPListTemplateType.DiscussionBoard)
var DiscName = dlist.Title;
var DiscCount = dlist.Folders.Count;
tot += DiscCount;
dt.Rows.Add(DiscName, DiscCount);
discGrid.DataSource = dt;
totItems.Text = tot.ToString();

Get Details from a list using LINQ

var dc = new SPLinqDataContext(SPContext.Current.Web.Url);
var conts = dc.GetList("contacts");
var myquery = from c in conts
select new
mygrid.DataSource = myquery;

Get Library Details

SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPListCollection ls = web.Lists;
var Name = "";
var Count = 0;
var Total = 0;
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Count", typeof(string));
foreach (SPList list in ls)
if (list.BaseTemplate == SPListTemplateType.DocumentLibrary)
Name = list.Title;
Count = list.Items.Count;
table.Rows.Add(Name, Count);
Total += Count;
table.Rows.Add("Total", Total);
dispGrid.DataSource = table;

Get file details from a particular library

SPSite currSite = SPContext.Current.Site;
SPWeb myWeb = currSite.OpenWeb();
SPList mylist= myWeb.Lists["mydoc"];
SPListItemCollection col = mylist.Items;
var FileName="";
var User="";
DataTable table = new DataTable();
table.Columns.Add("FileName", typeof(string));
table.Columns.Add("User", typeof(string));
foreach (SPListItem item in col)
FileName = item.Name;
User = item.File.Author.ToString();
table.Rows.Add(FileName, User);
myGrid.DataSource = table;

Get details from a library using CAML query

string qry = "Your CAML query for library";
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
SPList list = web.Lists["mydoc"];
SPQuery query = new SPQuery();
query.Query = qry;

DataTable dt = new DataTable();
dt = list.GetItems(qry).GetDataTable();
myGrid.DataSource = dt;

Get details of a library based on user selected from a dropdown box

protected SPSite site;
protected SPWeb web;
protected SPList myList;
protected SPListItemCollection itemColl;
protected DataTable dt;
protected SPUserCollection users;
protected void Page_Load(object sender, EventArgs e)
site = SPContext.Current.Site;
web = site.OpenWeb();
myList = web.Lists["myDoc"];
dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Count", typeof(string));
if (!IsPostBack)
users = web.SiteUsers;
foreach (SPUser s in users)
protected void bindData()
itemColl = myList.Items;
var fname = "";
var auth = "";
foreach (SPListItem item in itemColl)
fname = item.Name;
auth = item.File.Author.ToString();
myGrid.DataSource = dt;
protected void DDList_SelectedIndexChanged(object sender, EventArgs e)

Assigning total count to a footer

if (e.Row.RowType == DataControlRowType.DataRow)
totalItems += Convert.ToInt32(e.Row.Cells[1].Text);
else if (e.Row.RowType == DataControlRowType.Footer)

Save data to field from webpart

SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
SPList myList = web.Lists["details"];
SPListItem listItem = myList.Items.Add();
listItem["Name"] = txtName.Text;
listItem["Age"] = txtAge.Text;
listItem["Qualification"] = txtQualification.Text;