Tuesday, May 31, 2011

Sharepoint 2010 get logged in user name

string strCurrentUser = SPContext.Current.Web.CurrentUser.LoginName

SPContext:
Represents the context of Http request in Microsoft Sharepoint Foundation.
Use the SpContext class to return context information about objects as the 1)current web application 2)site collection 3)site 4)list or list items

Current:
Current Property provides properties that access various objects within the current SharPoint Foundation context,for example the current list,web site , site collection or Web application.

Monday, May 30, 2011

Sharepoint Site.Openweb() method

returns the specified website from the site collection.

Overload List


  NameDescription
Public method OpenWeb() Returns the Web site that is associated with the URL that is used in an SPSite constructor.
Public method OpenWeb(Guid) Returns the Web site with the specified GUID.
Public method OpenWeb(String) Returns the Web site that is located at the specified server-relative or site-relative URL.
Public method OpenWeb(String, Boolean) Returns the Web site that is located at the specified server-relative or site-relative URL based on a Boolean value that specifies whether the exact URL must be supplied.

What is C Sharp Using statement

The Using statement in C# allows you to define the scope of an object lifetime, when the end of the using satament is reached  the object Dispose() will be called immediatly.

using (SqlConnection conn = new SqlConnection(connString))
{
     SqlCommand cmd = conn.CreateCommand();
     cmd.CommandText = "SELECT * FROM Customers";
     conn.Open();
     using (SqlDataReader dr = cmd.ExecuteReader()) {
          while (dr.Read())
          // Do Something...
     }
}

This is extremly useful when we need to release a resourece intensive object, like database connection object or a transaction scope                 
                                                                          read more

Friday, May 27, 2011

Different ways of accessing list programatically

In SP 2010 you can programmatically access and code against list in a number of different ways using :

1. Server side Object Model
2. Client Side Object model
3. WCF Data Services
4. List Web Services
5. Customn WCF Services
6. Custom ASP.Net services

Sharepoint 2010 Lists

Overview of Sharepoint List:
A list is essentially a type of data structure in Sharepoint
The data in the list is refered to as list item
A list item comprises of field and field contains specific data.There are many types of list in sharepoint like Claendar list,Announcemnet list, custom list. Lists also include document libraries

Another more advanced type of Custom list is the External List . The external List dynamically loads data from external datasource into sharepoint list

The above diagram illustrates the conceptual structure of a list .

The Sharepoint List Object Model:

Exploring SharePoint Site in Visual Studio 2010

Start visual Studio 2010 Goto View --> Server Explorer.

Sharepoint 2010 designer adding javascript to pages

A simple way to add javascript code in Sharepoint pages in designer

1. Open the site in Sharepoint designer
2. Slect the desired pages from 'Site Pages' in designer
3. Goto Split or Code mode and add this below javascript code :-)

 4. You will get analert message when page loads !!