Monday, November 5, 2012

Create an ASP.NET Page (Application Page) for SharePoint 2010/2013

  1. Visual Studio 2010 or 2013 --> New Project --> SharePoint --> 2010 node --> Empty SharePoint Project.
    Name: SharePointApplicationProject --> OK.
  2. The SharePoint Customization Wizard appears. This wizard enables you to select the site that you will use to debug the project and the trust level of the solution.
  3. Choose the Deploy as a farm solution option button, and then choose the Finish button to accept the default local SharePoint site.
  4. Right click on the project --> Add New Item --> Application Page, Name:TestPage.aspx
    The Visual Web Developer designer displays the application page in Source view where you can see the page's HTML elements. The designer displays the markup for several Content controls. Each control maps to a ContentPlaceHolder control that is defined in the default application master page.
  5. Use VS --> View --> Toolbox to drag and drop control on the source view. Under
    Under PlaceHolderMain add these tags

    <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />    
    <asp:listbox id="lstLists" runat="server"></asp:listbox>
    And in code behind
    protected void btnSubmit_Click(object sender, EventArgs e){SPWeb web = SPContext.Current.Web;lstLists.Items.Clear();lstLists.Items.Add("Lists in '" + web.Title + "' site");lstLists.Items.Add("");foreach (SPList list in web.Lists){    lstLists.Items.Add(list.Title);}}
  6. To execute the page, Solution Explorer --> Right Click on Application Page -->Set as Startup Item.
  7. F5..
  8. To use a different master page or your own custom master page use the below code

        protected override void OnPreInit(EventArgs e)

        {
            base.OnPreInit(e);

            SPWeb Web = SPContext.Current.Web;
            string strUrl = Web.ServerRelativeUrl + "/_catalogs/masterpage/v4.master";
            this.MasterPageFile = strUrl;
        }


No comments:

Post a Comment