[Translation] no.9355 SharePoint pages (4) Application page

Source: Internet
Author: User

Create an applicationProgramPage
On the surface, the application page is the same as the website page, which provides functions to SharePoint users. However, when using the application page, you can know the pages that can be accessed by websites or website sets in Sharepoint. In addition, because the application page cannot be customized, you do not need to store multiple copies in the content database.CodeIt can be compiled into a DLL assembly, so that both the access performance and execution performance will be better than the website page. From the developer's perspective, the biggest difference between an application page and a website page is that an application page allows Inline code on the page.

Now, let's create an application page file. Open Visual Studio as an administrator and select Create project. An application page project cannot be created independently. You can only create an empty SharePoint project first. Therefore, create an empty project and name it customapplicationpage.

In the SharePoint custom wizard, select "Farm solution deployment" and click "finish. After the project is created, right-click customapplicationpage in the solution browser and choose add> new item from the menu ". In the create Item dialog box, select "application page" and name it "custom. aspx ". Visual Studio creates an application page and opens the Code view of the ASPX page. Because there is no available application page design view, we can only manually add code. By default, the placeholder ID of the default. master page is applied to the application page. As shown in code 10-4, the default application page initial code is:

The first line of the HTML tag specifies to include the compiled output assembly. The application page compilation requires the application of the Assembly in the GAC folder. In the second row, the Microsoft. Sharepoint. applicationpages referenced by the page is specified, so that the Members and types in the namespace can be directly used by user code.

Next, the HTML Tag registers some application control objects and prefixes. Prefix is the alias of the associated namespace and class name. In the @ page command, in addition to setting the codebehind attribute to instruct the code to hide the file, you can also set dynamicmasterpagefile to set the master page of the page as the default master page "~ Masterurl/Default. Master ". If you need to use a custom master page, you need to set masterpagefile to replace the dynamicmasterpagefile attribute.

The last part is the four contentplaceholder of the master page. Table 10-1 displays placeholders and their functions:

Table10-1: Template items on the application pageContentplaceholder


placeholder

description

placeholderadditionalpagehead

you need to add a content area in the tag, such as a script or style table reference. However, the page title cannot be set here, so that the page title is an independent placeholder placeholderpagetitle .

placeholdermain

main content area of the page.

placeholderpagetitle

set the area of the browser title.

placeholderpagetitleintitlearea

The title area displayed on the page.

Next, let's take a closer look at the project structure in the Visual Studio solution browser. Note that Visual Studio creates a layouts folder, Which is mapped to the SharePoint response folder during deployment. In addition, Visual Studio creates a sub-folder named after the project name in the layouts folder, and adds the created application page to the folder. Every page added to this project is saved in this folder. From the perspective of deployment, this is a great practice. Visual Studio does not directly deploy all the files to the layouts folder, this makes it easier to find custom application pages during definition. The solution Resource Manager view is as follows:

After learning about the content, we continue to complete our first application page. We will build an application page to display the usage information of the current Assembly. Reference10-1Placeholder information in, such as code10-5AddHtmlMark.

Because no style sheet or script information needs to be added, placeholderadditionalpagehead is not used. In placeholdermain, we create an HTML table to display the statistics of the website set. The table uses the <tr> element to create six rows. Each row contains two <TD> elements to create cells. The first cell is the description of the display content, and the second cell is used to display statistics. The title is added to placeholderpagetitle and placeholderpagetitleintitlearea.

After building the HTML code, we start to write and execute the code. Right-click the View window and select "view code" from the menu. This will open the hidden code file custom on the application page. aspx. CS: Execute the code when loading the page, as shown in code 10-6. The page_load event execution content:

In the first line of the page_load event, get the spsite object through the context object spcontext. Current of SharePoint. (For more information about the SharePoint object model, see Chapter 3 "Introduction to the SharePoint Object Model"). Then, we create a useageinfo object, this object provides statistics on all usage information of our website set. After that, we set the tags that display the SharePoint site set usage information.

After the code is complete, we can start and debug the application page. Set the application page to the project launch page, as shown in 10-24. On the customapplicationpage property page of the project, locate the launch attribute and set it to the application page, in the first line of the page_load event, set the breakpoint. Click F5 to start and go to the application page we just created.

During debugging, Visual Studio deploys the folder to the layouts folder configured in Sharepoint, and 10-25 displays the application page just created. When debugging is stopped, Visual Studio automatically recycles all the content. Therefore, if the project debugging is complete and needs to be used, right-click the project in Solution Explorer, select "deployment" from the menu to complete solution deployment.

Now let's review the previous work. Create the first application page in a blank SharePoint project, and Visual Studio automatically creates the ing file structure during deployment. As a developer, we. the page layout is created in the placeholder Of the. NET page, and the Execution Code is written in the code file (Visual Studio does not provide a visual design interface for the Application page). Then, press F5 to deploy and debug the application page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.