Thursday, December 24, 2009

SharePoint Important Links


FBA Links

FBA Limitations References

CSS Reference Chart for SharePoint 2007


CSS Reference Chart for SharePoint 2007


Thursday, December 17, 2009

Code to Create Sites List in SharePoint


Created Sites List

Last but not least, create a list that contains all sites that were created with your site provision. This list will be useful to monitor exiting sites and most importantly you could execute CAML queries to retrieve sites from the list.

For example, if you want to display the last five sites that were created. You can do it simply by using this CAML query:
SPListItemCollection itemColl = null; 
using (SPSite site = new SPSite (SPContext.Current.Site.Url)) 
 { 
   using (SPWeb web = site.OpenWeb ()) 
   { 
     SPList list = web.Lists [“CreatedSitesList”];  
     SPQuery qry = new SPQuery(); 
     qry.Query = ""; 
     qry.ViewFields = ""; 
     qry.RowLimit = 5; 
     itemColl = list.GetItems(qry); 
 } 
}

How to Create Sub Site and Site Collection in SharePoint by using object model


New SharePoint Site

When you create a new SharePoint site there are two options:
   1. A new Site Collection - use the Add method of the SPWebCollection class.
   2. A new Sub Site - use the Add method of the Webs collection of the SPWeb class.

The following examples create a new Site Collection and a new Sub Site that is based on information gathered from the request form and stored in the Site Request List.
Create Sub Site


private string CreateSubSite(SPListItem item) 
{ 
   SPWeb newWeb = null; 
   string url = string.Empty; 
   try 
   { 
      SPSecurity.RunWithElevatedPrivileges(delegate()  
     { 
        using (SPSite site = new SPSite(form.HostUrl)) 
       { 
          site.AllowUnsafeUpdates = true; 
          using (SPWeb web = site.OpenWeb ()) 
         { 
              string relativeUrl = item["ID"].ToString().PadLeft(6, '0'); 
             web.AllowUnsafeUpdates = true; 
            newWeb = web.Webs.Add(relativeUrl, 
              item["Title"].ToString(), 
              item["Description"].ToString(), 
              1033, 
              item["Template"].ToString(), 
              true, false); 
           url = newWeb.Url; 
          newWeb.Dispose(); 
         } 
       } 
    }); 
} 
catch (Exception ex) 
{
 // handle exception 
} finally
{ 
     if (newWeb == null) 
        { 
         newWeb.Dispose(); 
        } 
      } return url; 
}

Create Site Collection
private static string CreateSiteCollection(SPListItem item) 
{ 
  SPSite site = null; 
  SPWeb newWeb = null; 
  string url = string.Empty; 
  try { 
     SPSecurity.RunWithElevatedPrivileges(delegate() 
       { 
         SPWebApplication webApplication = null; 
         webApplication = SPWebApplication.Lookup(new Uri (YourHostUrl)); 
         string relativeUrl = ""; 
         relativeUrl = item["ID"].ToString().PadLeft(6, '0'); 
         site = webApplication.Sites.Add(YourHostUrl + "/" + relativeUrl, 
                                         item ["Title"].ToString (), 
                                         item["Description"].ToString (), 
                                         1033, 
                                         item["Template"].ToString (), 
                                         siteAdministratorLoginName, 
                                         siteAdministratorName, 
           ;                             siteAdministratorEmail); 
         newWeb = site.OpenWeb(); 
         url = newWeb.Url; 
         web.Dispose (); 
         site.Dispose (); 
       }); 
      }  
  catch (Exception ex) 
   { 
     // handle exception
    } 
   finally 
   {
      if (newWeb!= null) 
       { 
         newWeb.Dispose(); 
       } 
      if (site != null)
       { 
         site.Dispose(); 
        } 
    } 
 return url; 
}


Can't set the selected item of the dropdownlist in sharepoint

Question: Can't set the selected item of the dropdownlist in sharepoint


Answer::


Mark EnableViewState property of page directive to true in .aspx page



<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="CodeBehindAmit.ShowList" EnableViewState="true" EnableViewStateMac="true" AutoEventWireup="true" %>




Wednesday, December 16, 2009

Useing SPGridView in Code Behind

1] Create ASPX and add following code

<%@ Register Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    Namespace="Microsoft.SharePoint.WebControls" TagPrefix="cc1" %>


<cc1:SPGridView ID="SPGridView1" runat="server" AutoGenerateColumns="False" >
    </cc1:SPGridView>
    <cc1:SPDataSource ID="SPDataSource1" runat="server">
    </cc1:SPDataSource>

2] Create Cs file and add following code

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI ;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;

public class ShowList : LayoutsPageBase
{
public SPGridView SPGridView1;
public SPDataSource SPDataSource1;
protected override void OnLoad(EventArgs e)
{
SPWeb site = Microsoft.SharePoint.WebControls.SPControl.GetContextWeb(Context);
SPList mylist = site.Lists["Tasks"];
this.SPDataSource1.List = mylist;
BoundField colTitle = new BoundField();
colTitle.DataField = "Title";
colTitle.HeaderText = "Title";
this.SPGridView1.Columns.Add(colTitle);
this.SPGridView1.DataSource = SPDataSource1;
int a =this.SPGridView1.Columns.Count;
this.SPGridView1.DataBind();
int b = this.SPGridView1.Columns.Count;
}