January 26, 2012

Sharepoint 2007 Programming - Create a web application


SharePoint Object Model

SharePoint object model consists of a group of object that will help programmer to add programming logic to a SharePoint site. The base namespace for this is Microsoft.SharePoint.

The classes that will be typically used are SPWebApplication, SPSite, SPWeb, SPList, SPListCollection and so on. 

How to create a web application in Sharepoint 2007?

Open Visual Studio 2005/2008/2010, create a new Web application and set a reference to Microsoft.SharePoint.dll. If you are using Visual Studio 2010 then change the target framework to 3.5. 

In Design view, use the Toolbox to add a label, a text box, and a button to Default.aspx. To open the Toolbox, click Toolbox on the View menu. To open the code-behind file named Default.aspx.cs, double-click the button you added in the previous step. 

At the beginning of the file, add using directives (Imports statements in Visual Basic) that reference the Microsoft.SharePoint and Microsoft.SharePoint.Utilities, as follows: 

using Microsoft.SharePoint; 
using Microsoft.SharePoint.Utilities; 

At the beginning of the class definition return the site collection object for the current request context as follows:
public partial class _Default : System.Web.UI.Page
{
   SPSite oSite = SPContext.Current.Site;
}

Create a method that uses the AllWebs property of the SPSite class, the AllUsers property of the SPWeb class, and the Groups property of the SPUser class within nested foreach statements, in order to return a user object for the user name specified in the text box, as well as the list of groups to which that user belongs.
Within the default class in Default.aspx.cs, add the following method to return the users and groups for each Web site in the current site collection:

protected void GetSitesAndGroups()
{
   string strUser = SPEncode.HtmlEncode(TextBox1.Text) +
      " is a user in the following groups:<BR>";

   SPWebCollection collWebs = oSite.AllWebs;

   foreach (SPWeb oWebsite in collWebs)
   {
      string strGroups = "";

      /*Use AllUsers not Users to ensure you find the user*/
      SPUserCollection collUsers = oWebsite.AllUsers;
      foreach (SPUser oUser in collUsers)
      {
         if (oUser.LoginName.ToUpper() == TextBox1.Text.ToUpper())
         {
            SPGroupCollection collGroups = oUser.Groups;

            foreach (SPGroup oGroup in collGroups)
            {
               strGroups += SPEncode.HtmlEncode(oGroup.Name) +
                  "  ";
            }

            strUser += oWebsite.ServerRelativeUrl.ToString() +
               " -- " + strGroups + "<BR>";
         }
      }

      oWebsite.Dispose();
   }

      Label1.Text = strUser;
}

To run the code added in the previous step and avoid receiving an access denied error message, the user implementing the GetSitesAndGroups method must have Full Control permission. Add the following code to the Button1_Click event handler, which uses the RunWithElevatedPrivileges method to allow the current user to iterate through the users and groups of each Web site within the current site collection.

protected void Button1_Click(object sender, EventArgs e)
{
   SPSecurity.CodeToRunElevated elevatedGetSitesAndGroups = new SPSecurity.CodeToRunElevated(GetSitesAndGroups);
   SPSecurity.RunWithElevatedPrivileges(elevatedGetSitesAndGroups);
}

On the Debug menu, click Start Debugging, or press F5. If a Debugging Not Enabled dialog box appears, make sure Add a new Web.config file with debugging enabled is selected, and click OK.
The browser opens the page. When you type the logon name of a user on a site within the current site collection, the label displays the Web sites and groups to which the specified user belongs.

To run the application after creating it in Visual Studio 2005/2008/2010, navigate to http://Server_Name/_layouts/Web_Application_Name/Default.aspx.


Sharepoint Virtual Labs

If you have a decent internet connection and you do not want to go through the burden of installing the sharepoint environment on you laptop/desktop then Microsoft has found out a easy way for you to learn and practice Sharepoint 2007/2010. This is possible by using Microsoft Virtual Labs.

January 25, 2012

Create your first SharePoint Site

Before creating a SharePoint site we should create a Web application. Inside the web application we have to create a site collection. A site collection can have number of sites and sub sites. By default a site collection will have one site which will be the root site.

1) On the windows server go to Start-->Programs and open SharePoint Central Administration.
2) Go to Application Management tab and click on Create a Web Application under "Sharepoint web application management" section.
3) Fill the values and click on OK button.
4) Congratulations! You have created your first web application.

Once a web application has been created we are ready to create a site collection.

1) Go to Application Management tab and click on Create a Site Collection under "Sharepoint Site Management" section.
2) Select the Web Application you just created and fill rest of the values.


3) After you have filled in all the required information, you can click the OK button to start the provisioning process. WSS will provision a new site collection containing a top-level site. The top-level site will be created using the site template you selected.



4) Congratulations! You have now created a new WSS site collection which includes a top-level site created from the template you selected.

January 22, 2012

Configure Sharepoint Server on Laptop/Desktop


Configure Sharepoint Server on Laptop/Desktop

So here is the problem. You are a sharepoint developer and you want to install Windows SharePoint services(WSS) on your desktop/laptop. Since we can install WSS only on a server so I will give you some quick tips to create a SharePoint development environment quickly.
1)First you will need Desktop/Laptop with atleast 2GB RAM with windows XP/Vista/7 installed.
2)Download a virtual server (Microsoft or VMware).
3)Download a Server operating system (Windows 2003 or Windows 2008).
4)Download Windows SharePoint services 3.0 with service pack2.
5)Download Visual studio 2008 professional version.

Once you have downloaded all the above software you are ready to start the process of creating the sharepoint environment.

1)Install Virtual Server. Once Virtual server is installed Virtual Machine should be created. On this Virtual machine windows server operating system should be installed.

2)Once the windows server installation is complete then install Visual studio 2008 professional and Windows SharePoint Services on the virtual machine just created.

That's it now you are all set to create you first SharePoint site.


*****************************************************************
Free online C# tutorial. Learn easily, quickly and confidently. 
Visit today www.tutorialnode.com
*****************************************************************
Looking for cheap Business Process Management Solutions for your Business?

Visit official website of Enterprise Connections http://entconn.co.uk 
*****************************************************************

January 20, 2012

Important downloads for Sharepoint and .NET developers


Important downloads for Sharepoint and .NET developers

If you want to try out the full version of Visual Studio 2008 then you can use the below link to download it directly from Microsoft's website.
http://download.microsoft.com/download/8/1/d/81d3f35e-fa03-485b-953b-ff952e402520/VS2008ProEdition90dayTrialENUX1435622.iso

For sharepoint developers, to download Windows sharepoint services 3.0 with service pack 2 go to the below link:
http://www.microsoft.com/download/en/details.aspx?id=7006

To download Visual Studio 2008 extensions for Sharepoint visit the below url: 
http://www.microsoft.com/download/en/details.aspx?id=21082

Microsoft has launched Sharepoint Foundation 2010 for 64 bit machines. If you want to develop Sharepoint applications on a 64 bit laptop/Desktop with Windows Vista/7 installed then try Sharepoint foundation 2010:
http://www.microsoft.com/download/en/details.aspx?id=5970


To start the development you will need Visual Studio 2010. The evaluation version of this can be downloaded from the below url:
http://www.microsoft.com/visualstudio/en-us/try


There are very interesting training materials provided by Microsoft for learning framework 4.0 technology and Visual Studio 2010. This Training Kit includes presentations, hands-on labs, and demos.
http://www.microsoft.com/download/en/details.aspx?id=23507