Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Wednesday, November 30, 2011

Easy Way to Implement Ajax in SharePoint 2007 with UserControl.



Implementation of Ajax in SharePoint
·         First create one asp.net Ajax website.  You will get Ajax entries in web.config. fill the relevant sections of SharePoint Web.config carefully.
·         Copy ajaxcontroltookit dll to your bin folder.
·         Now copy the ajaxcontroltookit safe control to your SharePoint Web.config.
·         Now open your SharePoint site in SharePoint Designer.
·         Do as it is as the above thing.
·         Now add the register reference tab as below for Ajax Control Toolkit like this.
·         <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
·         Now add ScriptManager after the form tag within a Master Page. Add this as below.
·           <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" RunAt="Server" />
·         Now take a user control and place an update panel in that and place a grid inside the content template of update panel.
·         Now write your logic in ascx.cs file as shown below.


Ajax Ascx Page
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AjaxWebUserControl.ascx.cs" Inherits="AjaxWebUserControl" %>
<%@ Register Assembly="AjaxControlToolkit, Version=1.0.20229.20821, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"
    Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
    <asp:GridView ID="dgvTasks" runat="server" AutoGenerateColumns="False" CellPadding="4" PageSize="10"
        ForeColor="#333333" GridLines="Both" AllowPaging="True" OnPageIndexChanging="dgvTasks_PageIndexChanging">
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <Columns>
            <asp:BoundField DataField="Title" HeaderText="Title" />
            <asp:BoundField DataField="Status" HeaderText="Status" />
            <asp:BoundField DataField="Priority" HeaderText="Priority" />
        </Columns>
        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using System.Security;

public partial class AjaxWebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fillGrid();
        }
    }
    public void fillGrid()
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            SPWeb currentWeb = SPContext.Current.Web;
            using (SPSite site = new SPSite(currentWeb.Url))
            {
                using (SPWeb objWeb = site.OpenWeb())
                {
                    SPList lstTasks = objWeb.Lists["Tasks"];
                    SPListItemCollection myColl = lstTasks.Items;
                    if (myColl.Count > 0)
                    {
                        dgvTasks.DataSource = myColl.GetDataTable();
                        dgvTasks.DataBind();
                    }
                }
            }
        });
    }
    protected void dgvTasks_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        dgvTasks.PageIndex = e.NewPageIndex;
        fillGrid();
    }
}
Adding Ajax User Control to a WebPart.
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Security;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.Extensions;
[assembly:AllowPartiallyTrustedCallers]
namespace UserControlSample
{
    [Guid("ee10f4a4-4126-4350-967e-e49ea40ee7c7")]
    public class UserControlSample : System.Web.UI.WebControls.WebParts.WebPart
    {
        string strError = string.Empty;
        Control MyControl;
        public UserControlSample()
        {
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(strError);
            try
            {
                    MyControl.RenderControl(writer);
               
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }
        }
       
        protected override void CreateChildControls()
        {
            try
            {
               
                EnsurePanelFix();
                this.Controls.Clear();
                MyControl = this.Page.LoadControl("\\_LAYOUTS\\Custom UserControls\\AjaxWebUserControl.ascx");
                MyControl.ID = "myControl";
                this.Controls.Add(MyControl);
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        private void EnsurePanelFix()
        {
            ScriptManager.RegisterStartupScript
              (this,
               typeof(Control),
               "UpdatePanelFixup",
               "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;",
               true);
        }
    }
}


How to Make Linq Work in User Control of SharePoint 2007

Hi

First Copy the above lines of code after  <assemblies> tag

Now Paste these lines after Assemblies Tag

<add assembly="System.Core, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Design, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="System.Web.Extensions.Design, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Windows.Forms, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089"/>
____________________________________________________________________________
After this paste the following lines of code after the </system.web>
tag
<system.codedom>
                <compilers>
                        <compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
                                <providerOption name="CompilerVersion" value="v3.5"/>
                                <providerOption name="WarnAsError" value="false"/>
                        </compiler>
                        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
                                <providerOption name="CompilerVersion" value="v3.5"/>
                                <providerOption name="OptionInfer" value="true"/>
                                <providerOption name="WarnAsError" value="false"/>
                        </compiler>
                </compilers>
        </system.codedom>

Talk to SharePoint Through its Web Services

create a site definition from an existing site

Plan authentication methods (SharePoint Server 2010)

Using a custom webservice in a webpart

using System;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Security;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using System.Collections.Specialized;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Configuration;
using System.Data;
using System.Web.UI.HtmlControls;
[assembly: AllowPartiallyTrustedCallers]

namespace CustomWebServiceResult
{
    [Guid("bec42463-9e42-4ead-92ae-4723cf3f2c02")]
    public class CustomWebServiceResult : System.Web.UI.WebControls.WebParts.WebPart
    {
        GridView ServiceGridView;
        string strError = string.Empty;
        localhost.Service s = new localhost.Service();
        public CustomWebServiceResult()
        {
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(strError);
            try
            {
                ServiceGridView.RenderControl(writer);
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }
        }
        protected override void CreateChildControls()
        {

            try
            {
                ServiceGridView = new GridView();
                ServiceGridView.ID = "ServiceGridView";
                ServiceGridView.AutoGenerateColumns = false;

                BoundField bTitle = new BoundField();
                bTitle.HeaderText = "Task Name";
                bTitle.DataField = "Title";
                ServiceGridView.Columns.Add(bTitle);

                BoundField bStatus = new BoundField();
                bStatus.HeaderText = "Task Status";
                bStatus.DataField = "Status";
                ServiceGridView.Columns.Add(bStatus);

                BoundField bPriority = new BoundField();
                bPriority.HeaderText = "Task Priority";
                bPriority.DataField = "Priority";
                ServiceGridView.Columns.Add(bPriority);

                BoundField bStartDate = new BoundField();
                bStartDate.HeaderText = "Task Start Date";
                bStartDate.DataField = "StartDate";
                ServiceGridView.Columns.Add(bStartDate);
                s.UseDefaultCredentials = true;
                ServiceGridView.DataSource = s.getTasks();
                ServiceGridView.DataBind();
                this.Controls.Add(ServiceGridView);
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
    }
}

Writing a Custom WebService for SharePoint

using System;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using Microsoft.SharePoint;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    //DataView dv;
    public Service()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    [WebMethod]
    public DataSet getTasks()
    {
        try
        {
            DataSet dv = new DataSet();
            DataTable dt = new DataTable();
            //dv = new DataView();
            SPSite obsite = new SPSite("http://vlnrm:100/Prasad");
            SPWeb currentWeb = obsite.AllWebs["Prasad"];
            dt.TableName = "Prasad";
            dt.Columns.Add("Title");
            dt.Columns.Add("Status");
            dt.Columns.Add("Priority");
            dt.Columns.Add("StartDate");
            SPList Tasks = currentWeb.Lists["Tasks"];
            string strTitle = string.Empty;
            if (Tasks != null)
            {
                SPListItemCollection listItems = currentWeb.Lists["Tasks"].Items;
                if (listItems.Count > 0)
                {
                    foreach (SPListItem item in listItems)
                    {
                        if (item["Title"] != null)
                        {
                            strTitle = item["Title"].ToString();
                        }
                        else
                        {
                            strTitle = "--";
                        }
                        DataRow drow = dt.NewRow();
                        drow["Title"] = strTitle;
                        drow["Status"] = item["Status"].ToString();
                        drow["Priority"] = item["Priority"].ToString();
                        drow["StartDate"] = item["StartDate"].ToString();
                        dt.Rows.Add(drow);

                    }
                    dv.Tables.Add(dt);
                }
            }
            return dv;
        }
        catch (Exception ex)
        {
            string str = ex.ToString();
            Console.WriteLine(str);
            DataSet dsErr = new DataSet(); ;
            DataTable dt1 = new DataTable();
            dt1.Columns.Add("err");
            DataRow dr1;
            dr1 = dt1.NewRow();
            dr1["err"] = ex.ToString();
            dt1.Rows.Add(dr1);
            dsErr.Tables.Add(dt1);
            return dsErr;
        }
    }

}

How to programmatically set the content type while creating a list item

If you create a new list item using the API without setting the content type id you will create a new item using the default content type.  However if you want to create a new list item using a different content type you will need to set the Content Type ID field.
The example below creates a list item using a content type called "Log" in a list called "HistoryLog".
using (SPSite site = new SPSite("http://intranet/"))
{
  using (SPWeb rootWeb = site.OpenWeb())
  {
    SPList historyLog = rootWeb.GetListFromUrl("/lists/historylog/allitems.aspx");
    SPListItem item = historyLog.Items.Add();
    item["LogType"] = "Warning";
    item["LogMessage"] = "Message .....";

    // set the content type id
    item["Content Type ID"] = rootWeb.ContentTypes["Log"].Id;
    
    item.Update();
  }
}

Validating WebPart Properties

Nothing is more annoying than configuring a web part by changing its properties and then hitting ok only to see the web part display an error that a property is invalid - and having to open the properties pane again to fix the problem.
To avoid this, best practice is to validate the data entered in the "set" of the web part property. For example, if I have a web part property that needs a comma delimited array of numbers (for example 1,2,3,4) and I don't want to build a tool part just for that, I can still build a property like this:
public string NumberArray
{
    get{return _numberArray;}
    set{_numberArray=value;}
}
The problem with the code above is that it is not validating that the string entered is indeed an array of numbers. To do that, I could change the code to something more like this:
public string NumberArray
{
    get{return _numberArray;}
    set{
          string [] arr = value.split(',');
          foreach (string item in arr)

          {
             int i;
             if(!int.TryParse(item,out i))
                throw new Exception("The item \""+item+"\" is not a valid number");
          }

_numberArray=value;}

}
This will do what I want - preven the user from closing the web part properties pane before fixing the error in the property, but it will not display the nice informative error to the user. Instead, it will show a generic error "An error has occurred" despite the fact that I specified what the error was when I threw the error!
Why? because to do that the exception must be of type WebPartPageUserException.
So the correct code for validating my sample property would be:
public string NumberArray
{
    get{return _numberArray;}
    set{
          string [] arr = value.split(',');
          foreach (string item in arr)
          {

             int i;
             if(!int.TryParse(item,out i))
                throw new WebPartPageUserException("The item \""+item+"\" is not a valid number");
          }


_numberArray=value;}
}

Now - when the users put an invalid value in my property they will be notified that it is invalid, and which value it was.

Sample Code Custom Master Page

<%@Master language="C#"%>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
<HTML dir="<%$Resources:wss,multipages_direction_dir_value%>" runat="server" xmlns:o="urn:schemas-microsoft-com:office:office">
<HEAD runat="server">
 <META Name="GENERATOR" Content="Microsoft SharePoint">
 <META Name="progid" Content="SharePoint.WebPartPage.Document">
 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
 <META HTTP-EQUIV="Expires" content="0">
 <SharePoint:RobotsMetaTag runat="server"/>
 <Title ID=onetidTitle><asp:ContentPlaceHolder id=PlaceHolderPageTitle runat="server"/></Title>
 <SharePoint:CssLink runat="server"/>
 <SharePoint:Theme runat="server"/>
 <SharePoint:ScriptLink language="javascript" name="core.js" Defer="true" runat="server"/>
 <SharePoint:CustomJSUrl runat="server"/>
 <SharePoint:SoapDiscoveryLink runat="server"/>
 <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
 <SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
 <meta name="Microsoft Theme" content="Petal 1011, default">
</HEAD>
<BODY scroll="yes" onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();">
  <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
   <WebPartPages:SPWebPartManager id="m" runat="Server"/>
<table width="100%">
<tr>
<td>
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
<table align="right">
<tr>
<td align="right">
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" id="DelegateControl1"/>
</td>
</tr>
</table>
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
   <table width="100%">
   <tr>
   <td>
     <asp:ContentPlaceHolder ID="WSSDesignConsole" runat="server">
  <wssuc:DesignModeConsole id="IdDesignModeConsole" runat="server"/>
 </asp:ContentPlaceHolder>
   </td>
   </tr>
   <tr>
   <td>
   <asp:ContentPlaceHolder id="PlaceHolderGlobalNavigation" runat="server">
  <table CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%">
  <tr>
   <td colspan=4 class="ms-globalbreadcrumb">
   <span id="TurnOnAccessibility" style="display:none">
      <a href="#" class="ms-skip" onclick="SetIsAccessibilityFeatureEnabled(true);UpdateAccessibilityUI();return false;">
   <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,master_turnonaccessibility%>" EncodeMethod="HtmlEncode"/></a>
   </span>
   <A href="javascript:;" onclick="javascript:this.href='#mainContent';" class="ms-skip" AccessKey="<%$Resources:wss,maincontent_accesskey%>" runat="server">
   <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,mainContentLink%>" EncodeMethod="HtmlEncode"/></A>
   <table cellpadding=0 cellspacing=0 height=100% class="ms-globalleft">
     <tr>
   <td class="ms-globallinks" style="padding-top: 2px;" height=100% valign=middle>
    <div>
     <span id="TurnOffAccessibility" style="display:none">
    <a href="#" class="ms-acclink" onclick="SetIsAccessibilityFeatureEnabled(false);UpdateAccessibilityUI();return false;">
    <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,master_turnoffaccessibility%>" EncodeMethod="HtmlEncode"/></a>
     </span>
     <asp:ContentPlaceHolder id="PlaceHolderGlobalNavigationSiteMap" runat="server">
    <asp:SiteMapPath SiteMapProvider="SPSiteMapProvider" id="GlobalNavigationSiteMap" RenderCurrentNodeAsLink="true" SkipLinkText="" NodeStyle-CssClass="ms-sitemapdirectional" runat="server"/>
     </asp:ContentPlaceHolder>
     </div>
    </td>
     </tr>
   </table>
   <table cellpadding="0" cellspacing="0" height=100% class="ms-globalright">
    <tr>
     <td valign="middle" class="ms-globallinks" style="padding-left:3px; padding-right:6px;">
     <SharePoint:DelegateControl runat="server" ControlId="GlobalSiteLink0"/>
     </td>
    <td valign="middle" class="ms-globallinks">
   <wssuc:Welcome id="IdWelcome" runat="server" EnableViewState="false">
   </wssuc:Welcome>
    </td>
    <td style="padding-left:1px;padding-right:3px;" class="ms-globallinks">|</td>
     <td valign="middle" class="ms-globallinks">
    <table cellspacing="0" cellpadding="0">
     <tr>
      <td class="ms-globallinks">
     <SharePoint:DelegateControl ControlId="GlobalSiteLink1" Scope="Farm" runat="server"/></td>
      <td class="ms-globallinks">
     <SharePoint:DelegateControl ControlId="GlobalSiteLink2" Scope="Farm" runat="server"/></td>
     </tr>
    </table>
     </td>
     <td valign="middle" class="ms-globallinks">&nbsp;
    <a href="javascript:TopHelpButtonClick('NavBarHelpHome')" AccessKey="<%$Resources:wss,multipages_helplink_accesskey%>" id="TopHelpLink" title="<%$Resources:wss,multipages_helplinkalt_text%>" runat="server"><img align='absmiddle' border=0 src="/_layouts/images/helpicon.gif" alt="<%$Resources:wss,multipages_helplinkalt_text%>" runat="server"></a>
     </td>
     <td class="ms-siteactionsmenu" id="siteactiontd">
     <SharePoint:SiteActions runat="server" AccessKey="<%$Resources:wss,tb_SiteActions_AK%>" id="SiteActionsMenuMain"
      PrefixHtml="&lt;div&gt;&lt;div&gt;"
      SuffixHtml="&lt;/div&gt;&lt;/div&gt;"
      MenuNotVisibleHtml="&amp;nbsp;">
      <CustomTemplate>
      <SharePoint:FeatureMenuTemplate runat="server"
       FeatureScope="Site"
       Location="Microsoft.SharePoint.StandardMenu"
       GroupId="SiteActions"
       UseShortId="true"
       >
       <SharePoint:MenuItemTemplate runat="server" id="MenuItem_Create"
        Text="<%$Resources:wss,viewlsts_pagetitle_create%>"
        Description="<%$Resources:wss,siteactions_createdescription%>"
        ImageUrl="/_layouts/images/Actionscreate.gif"
        MenuGroupId="100"
        Sequence="100"
        UseShortId="true"
        ClientOnClickNavigateUrl="~site/_layouts/create.aspx"
        PermissionsString="ManageLists, ManageSubwebs"
        PermissionMode="Any" />
       <SharePoint:MenuItemTemplate runat="server" id="MenuItem_EditPage"
        Text="<%$Resources:wss,siteactions_editpage%>"
        Description="<%$Resources:wss,siteactions_editpagedescription%>"
        ImageUrl="/_layouts/images/ActionsEditPage.gif"
        MenuGroupId="100"
        Sequence="200"
        ClientOnClickNavigateUrl="javascript:MSOLayout_ChangeLayoutMode(false);"
        />
       <SharePoint:MenuItemTemplate runat="server" id="MenuItem_Settings"
        Text="<%$Resources:wss,settings_pagetitle%>"
        Description="<%$Resources:wss,siteactions_sitesettingsdescription%>"
        ImageUrl="/_layouts/images/ActionsSettings.gif"
        MenuGroupId="100"
        Sequence="300"
        UseShortId="true"
        ClientOnClickNavigateUrl="~site/_layouts/settings.aspx"
        PermissionsString="EnumeratePermissions,ManageWeb,ManageSubwebs,AddAndCustomizePages,ApplyThemeAndBorder,ManageAlerts,ManageLists,ViewUsageData"
        PermissionMode="Any" />
      </SharePoint:FeatureMenuTemplate>
      </CustomTemplate>
     </SharePoint:SiteActions>
     </td>
     </tr>
  
   </table>
   </td>
     </tr>
     </table>
   </asp:ContentPlaceHolder>
   </td>
   </tr>
   <tr>
   <td colspan="6">
   <table width="100%" bgcolor="aqua">
   <tr>
   <td>
   <a href="#" style="text-decoration:none;color:purple"><p><font size="2px"><center>Home</center></font></p></a>
   </td>
   <td>
   <a href="#" style="text-decoration:none;color:purple"><p><font size="2px"><center>Lists</center></font></p></a>
   </td>
   <td>
   <a href="#" style="text-decoration:none;color:purple"><p><font size="2px"><center>Document Libraries</center></font></p></a>
   </td>
   <td>
   <a href="#" style="text-decoration:none;color:purple"><p><font size="2px"><center>Picture Libraries</center></font></p></a>
   </td>
   <td>
   <a href="#" style="text-decoration:none;color:purple"><p><font size="2px"><center>TopSite</center></font></p></a>
   </td>
   </tr>
   </table>
   </td>
   </tr>
   </table>
   <table width="100%">
   <tr>
   <td>
 
    <asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat="server"/>
 
   </td>
   </tr>
   <tr>
   <td>
 
    <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server">
    </asp:ContentPlaceHolder>
 
   </td>
   </tr>
   </table>
   <asp:Panel Visible="false" ID="pnlplaceholders" runat="server">
    <asp:ContentPlaceHolder id="PlaceHolderLeftNavBarDataSource" runat="server" />
     <asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat="server" />
     <asp:ContentPlaceHolder id="PlaceHolderLeftNavBarTop" runat="server"/>
     <asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server"></asp:ContentPlaceHolder>
     <asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat="server"></asp:ContentPlaceHolder>
     <asp:ContentPlaceHolder id="PlaceHolderLeftNavBarBorder" runat="server"></asp:ContentPlaceHolder>
     <asp:ContentPlaceHolder id="PlaceHolderBodyLeftBorder" runat="server"></asp:ContentPlaceHolder>
     <asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server"></asp:ContentPlaceHolder>
     <asp:ContentPlaceHolder id="PlaceHolderUtilityContent" runat="server"/>
 <asp:ContentPlaceHolder id="PlaceHolderBodyAreaClass" runat="server"/>
 <asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat="server"/>
<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server" />
   <asp:ContentPlaceHolder id="PlaceHolderPageImage" runat="server" />
            <asp:ContentPlaceHolder id="PlaceHolderNavSpacer" runat="server" />
   </asp:Panel>
  </form>
</BODY>
</HTML>

How to Create a Minimal Master Page

One of the first tasks that you must complete when configuring a Microsoft Office SharePoint Server 2007 Web site is to create one or more master pages. A master page contains references to elements that you can share across multiple pages in an Office SharePoint Server 2007 site, such as navigation, search controls, logon controls, and banner images. A master page can also contain the cascading style sheet (CSS) and ECMAScript (JScript, JavaScript) references that define the overall look and feel of your site. Commonly, every site—and therefore every page—in your site collection uses the same master page to present a consistent user experience across the entire site collection. Depending on your needs, you can use a different master page for one or for all of the sites in your site hierarchy to distinguish the various areas of your portal.
Master Page Galleries
When you provision a site collection in Office SharePoint Server 2007, the system creates a master page gallery that contains all the master pages and page layouts for that site collection. If the site collection uses either the Publishing Portal or Collaboration Portal templates, the master page gallery includes several master pages that are provided with Office SharePoint Server 2007, such as BlueBand.master. These master pages are located in the path C:\Program%20Files\Common%20Files\Microsoft%20Shared\web%20server%20extensions\12\TEMPLATE\FEATURES\PublishingLayouts\MasterPages\, with other example .master pages. You can use any of these master pages as they are, or you can customize them fully to create unique branding for your site.
Why Start with a Minimal Master Page
Creating and completing a master page to begin your SharePoint site customization takes planning and time. If you can, you want to prevent having to rewrite or back out code you don't need in your master page. This topic shows you how to create a minimal master page that includes only the minimal functionality that Office SharePoint Server 2007 requires so that you have a stable platform upon which to build your own master pages. Creating a minimal master page can help you avoid the time-consuming process of backing code out of a pre-existing .master page such as BlueBand.master, or removing functionality and then building it back in when your customization needs change again.
NoteNote:
This topic supports using the Minimal Master Page described as a Site Master Page in Office SharePoint Server 2007. It does not support using the Minimal Master Page described in this topic as a System Master Page in Office SharePoint Server 2007. Using this content with Windows SharePoint Services 3.0 is not explicitly supported.
You can, of course, create a master page from scratch. However, we generally do not recommend this because a truly empty master page does not include all the content placeholders that the Office SharePoint Server 2007 page model needs to work correctly.
The sample code in the following procedure includes only what the Office SharePoint Server 2007 page model requires—necessary content placeholders and controls to work with the page layouts that are included in a default Office SharePoint Server 2007 installation. Office SharePoint Server 2007 requires a master page that includes a title, branding, logon functionality, search functionality, breadcrumb functionality, and basic structural elements such as page areas, separators, borders, consoles, and description placeholders.
The following procedure uses Office SharePoint Designer 2007 as the master page design environment. You can, however, use a text editor, a Web editor such as Microsoft Office SharePoint Designer 2007, or an integrated development environment (IDE) such as Microsoft Visual Studio 2005 to create a master page.
The master pages included with Office SharePoint Server 2007 are based on the SPWeb.CustomMasterUrl property of the SPWeb class in Windows SharePoint Services.

To create a minimal master page

  1. Open SharePoint Designer.
  2. On the File menu, click New, point to SharePoint Content, and then click the Page tab.
  3. Double-click Master Page to create a new master page.
  4. Click Design to show the master page in design view. You should see header and left margin areas and several content placeholders in the master page.
  5. Click Code to show the master page in code view.
  6. Copy the following code into the master page.

    <%-- Identifies this page as a .master page written in Microsoft Visual C# and registers tag prefixes, namespaces, assemblies, and controls. --%>
    <%@ Master language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
    <%@ Register TagPrefix="wssuc" TagName="DesignModeConsole" src="~/_controltemplates/DesignModeConsole.ascx" %>
    <%@ Register TagPrefix="PublishingVariations" TagName="VariationsLabelMenu" src="~/_controltemplates/VariationsLabelMenu.ascx" %>
    <%@ Register Tagprefix="PublishingConsole" TagName="Console" src="~/_controltemplates/PublishingConsole.ascx" %>
    <%@ Register TagPrefix="PublishingSiteAction" TagName="SiteActionMenu" src="~/_controltemplates/PublishingActionMenu.ascx" %>
    <%-- Uses the Microsoft Office namespace and schema. --%>
    <html>
      <WebPartPages:SPWebPartManager runat="server"/>
      <SharePoint:RobotsMetaTag runat="server"/>
    
      <%-- The head section includes a content placeholder for the page title and links to CSS and ECMAScript (JScript, JavaScript) files that run on the server. --%>
      <head runat="server">
        <asp:ContentPlaceHolder runat="server" id="head">
          <title>
            <asp:ContentPlaceHolder id="PlaceHolderPageTitle" runat="server" />
          </title>
        </asp:ContentPlaceHolder>
        <Sharepoint:CssLink runat="server"/>
        <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server" />
      </head>
      
      <%-- When loading the body of the .master page, SharePoint Server 2007 also loads the SpBodyOnLoadWrapper class. This class handles .js calls for the master page. --%>
      <body onload="javascript:_spBodyOnLoadWrapper();">
        <%-- The SPWebPartManager manages all of the Web part controls, functionality, and events that occur on a Web page. --%>
        <form runat="server" onsubmit="return _spFormOnSubmitWrapper();">
          <wssuc:Welcome id="explitLogout" runat="server"/>
          <PublishingSiteAction:SiteActionMenu runat="server"/>  
          <PublishingWebControls:AuthoringContainer id="authoringcontrols" runat="server">
            <PublishingConsole:Console runat="server" />
          </PublishingWebControls:AuthoringContainer>
          <%-- The PlaceHolderMain content placeholder defines where to place the page content for all the content from the page layout. The page layout can overwrite any content placeholder from the master page. Example: The PlaceHolderLeftNavBar can overwrite the left navigation bar. --%>
          <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" />
            <asp:Panel visible="false" runat="server">
            <%-- These ContentPlaceHolders ensure all default SharePoint Server pages render with this master page. If the system master page is set to any default master page, the only content placeholders required are those that are overridden by your page layouts. --%>
    <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea"  runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderPageImage" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderBodyLeftBorder" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderNavSpacer" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderTitleLeftBorder" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderTitleAreaSeparator" runat="server"/>
    <asp:ContentPlaceHolder ID="PlaceHolderMiniConsole" runat="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderCalendarNavigator" runat ="server" />
    <asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderPageDescription" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderBodyAreaClass" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderTitleAreaClass" runat ="server"/>
    <asp:ContentPlaceHolder id="PlaceHolderBodyRightMargin" runat="server" />
    </asp:Panel>
        </form>
      </body>
    </html>
    
  7. On the File menu, click Save As, provide a unique file name with the .master extension, and then save the file to the master page gallery (/_catalogs/masterpage) in your site collection.