Sunday, June 1, 2014

Application Pages Example in sharepoint 2013

Application Page Ex 1 : (Interest Calculator)

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InterestCalculator.aspx.cs" Inherits="SharePointProject20.Layouts.SharePointProject20.InterestCalculator" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead"
    ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <style type="text/css">
        .auto-style1 {
            width: 210px;
            height: 100px;
            background-color:navy;
            color:white;
        }
    </style>
</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <table class="auto-style1">
            <tr>
                <td>AMOUNT</td>
                <td>
                    <asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>RATE</td>
                <td>
                    <asp:TextBox ID="txtRate" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>PERIOD</td>
                <td>
                    <asp:TextBox ID="txtPeriod" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>INTEREST</td>
                <td>
                    <asp:TextBox ID="txtInterest" runat="server" ReadOnly="True"></asp:TextBox>
                </td>
            </tr>
        </table>
    <div>
 
        <asp:Button ID="btnCalculate" runat="server" OnClick="btnCalculate_Click" Text="Calculate Interest" />
 
    </div>
 
</asp:Content>

<asp:Content ID="PageTitle"
    ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Interest Calculator
</asp:Content>

<asp:Content ID="PageTitleInTitleArea"
     ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
    Calculates interest to be paid on loan taken
</asp:Content>


using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePointProject20.Layouts.SharePointProject20
{
    public partial class InterestCalculator : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            double amount, rate, period, interest;
            amount = Convert.ToDouble(txtAmount.Text);
            rate = Convert.ToDouble(txtRate.Text);
            period = Convert.ToDouble(txtPeriod.Text);
            interest = amount * rate * period / 100;
            txtInterest.Text = interest.ToString();
        }

    }
}

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomActionGroup Id="ApplicationsLinks"
   Title="Applications"
   Location="Microsoft.SharePoint.SiteSettings"
    Sequence="5">
  </CustomActionGroup>
  <CustomAction Id="InterestCalculatorLink"
                 Title="Interest Calculator"
                 Location="Microsoft.SharePoint.SiteSettings"
                 GroupId="ApplicationsLinks"
                 >
    <UrlAction Url="_layouts/SharePointProject20/InterestCalculator.aspx"/>
  </CustomAction>
</Elements>


Application Page Example 2 : (View all Lists and Libraries)

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewLists.aspx.cs" Inherits="SharePointProject21.Layouts.SharePointProject21.ViewLists" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
      <div>
 
        <asp:Label ID="lblListsLinks" runat="server"></asp:Label>
 
    </div>
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
View Lists
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
Links to all lists and libraries in this site
</asp:Content>


using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePointProject21.Layouts.SharePointProject21
{
    public partial class ViewLists : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SPWeb web = SPContext.Current.Web;
            foreach (SPList list in web.Lists)
                lblListsLinks.Text +=
                     "<a href='" +
                     list.DefaultViewUrl +
                     "'>" +
                     list.Title +
                     "</a><br />";
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="ViewListsLink"
                Title="View Lists"
                 Location="Microsoft.SharePoint.StandardMenu"
                 GroupId="SiteActions"
                 >
    <UrlAction Url="_layouts/SharePointProject21/ViewLists.aspx"/>
  </CustomAction>
</Elements>

No comments:

Post a Comment