Wednesday, December 22, 2010

Security Trimmed Controls in SharePoint

To apply permissions for a controls in SharePoint, use the below code.

<sharepoint:spsecuritytrimmedcontrol permissions=”ManageLists” runat=”server”>
Place your control(s) here

Available Permissions:


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;

Monday, October 4, 2010

What is a SharePoint?

Microsoft describes SharePoint 2010 as the business productivity platform for the enterprise and
the Internet.

*Collaborate — As you move throughout this book, you’ll see the notion of collaboration
is a very strong theme for SharePoint. This is because SharePoint is about bringing people
together through different types of collaboration, such as enterprise content management
(ECM), Web content management (WCM), social computing through the use of wikis or
blogs, creating dashboards to fulfill your business intelligence (BI) needs, and so on.
* Interoperability — SharePoint is also about bringing this collaboration together through
interoperability. This means Office client and Web-based document integration, and the
capability to build and deploy Office business applications (OBAs) — custom solutions that
integrate line-of-business (LOB) data with SharePoint and Office, integrating with Web 2.0
technologies, or deploying applications to the cloud. It also means enhanced security through
an evolved security model called Claims-Based Authentication that helps facilitate integration
with other line-of-business (LOB) systems.
*Platform — As you’ll see, SharePoint is a platform that supports not only interoperability
and collaboration but also extensibility, through a rich object model, a solid set of developer
tools, and a growing developer community.

These are three key themes that you will find crop up throughout most discussions of SharePoint
and implicitly through many of the capabilities you’ll get to explore throughout this book.
At its essence, SharePoint is a Web-based platform that provides the following:
* A set of native capabilities to support productivity and collaboration
* An extensible set of APIs and services
* A configuration engine that provides rich administrative abilities

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...