Customize and develop SharePoint pages
This book is about how to develop SharePoint 2010 in Visual Studio 2010. We will focus on how to create an applicationProgramPage. This is the only page type that provides an external template in Visual Studio. However, we will first briefly introduce the master page and how to create the page type.
Customize and create a master page
A master page is a Sharepoint page used to define general operations. The content and application pages of SharePoint mainly use v4.master. We can use SharePoint designer to view the v4.master master page.
Open SharePoint designer to connect to your SharePoint site. In 10-4, click the master page under the site object.
There are three master pages in the list. You can directly view all available master page files in the SharePoint master page library, and view http: // localhost/_ catalogs/masterpage/Forms/allitems through the following address in the browser. aspx. The default. master file on the master page is used for compatibility with the previous SharePoint version. A compatibility mode has been added to SharePoint 2010 to adapt to and migrate the previous SharePoint user interface. The master page minimal. Master page is a Sharepoint master page that meets minimum requirements.
Next let's take a look at the main v4.master master page. Double-click v4.master to open the management view interface of the master page, as shown in 10-5.
Click the [edit file] link in the Custom Area of the management view page. SharePoint designer opens the page editor. The page editor is a visual web designer Based on Visual Studio. You can divide the view andCodeSwitch between views. 10-6 is the design view.
Next, let's make a simple customization for the v4.master master page. We use SharePoint designer to create a new master page instead of directly editing the v4.master master page. This is a good practice. Click the entries on the master page on the left side to list all master pages. The ribbon toolbar on the top contains a "Blank master page" button. click the button to create a blank master page. 10-7 shows the "Blank master page" button.
Click "Blank master page" to create a blank master page. In the page editor, click the name to rename the master page to "mvmv4.master ". On the Edit page tab, select the Code view. When we compare the code on the customv4.master and v4.master master pages, you will notice that the Code on the blank master page is very small, and even the SharePoint functional area does not exist. Let's copy the code of v4.master to customv4.master. Select v4.master in Sharepoint to view its code view, as shown in Figure 10-8.
Move the mouse to the blank area and click, then press Ctrl + A and then press Ctrl + C to copy all the code, on the customv4.master page, click Ctrl + A and CTRL + V to paste and overwrite the original code. Now there are a lot of tags in the file. Switch to the split view on the tab at the bottom of the view editor, so that you can easily find the corresponding tag in the design view.
In the page editor, click the site icon in the upper left corner of the page. SharePoint designer will highlight the corresponding tag code in the Code view, as shown in 10-9:
Modify the value of the selected logoimageurl attribute to add a new logo to all websites. In this situation, we will manually copy an image file named awsiteicon.png to the {Your pointroot} \ Templates \ folder. In Chapter 11th "Packaging and deployment", we will describe how to use Visual Studio to package and deploy a solution for Sharepoint images. After changing the logoimageurl attribute, update it in the master page design view of SharePoint, as shown in Figure 10-10:
Modify the value of the selected logoimageurl attribute to add a new logo to all websites. In this situation, we will manually copy an image file named awsiteicon.png to the {Your pointroot} \ Templates \ folder. In Chapter 11th "Packaging and deployment", we will describe how to use Visual Studio to package and deploy a solution for Sharepoint images. After changing the logoimageurl attribute, update it in the master page design view of SharePoint, as shown in Figure 10-10:
If the modified Master page takes effectSharePoint designerIn the left-side Navigation Pane, click master.Customv4.masterRight-click the file and choose "set as default master page" from the menu ",10-11.
Visit the home page of the SharePoint site and you will see that the master page in use is what we just defined. If we create a new page, it will still use this master page. The effect of using mvmv4.master is shown in 10-12.
As we can see, it is very easy and convenient to create or modify a master page in SharePoint designer.
Please note that operations in SharePoint designer are a matter of consideration. First, all the edited content is saved in the content database. Second, there is no way to proceed.Source codeControl and change tracking.
Visual Studio helps us solve the second problem. Even though it does not provide a dedicated master page designer for designers, Visual Studio supports source code control for any type of SharePoint project. However, how does Visual Studio Add a master page to a Sharepoint project?
Next, let's create a blank SharePoint project named "mmmaster" in Visual Studio. If you want to add source code control to the project, you can select the option to add to source code controller. In the solution's SharePoint custom deployment wizard, select the sandbox Deployment Solution.
Because the SharePoint project in Visual Studio does not support master page deployment, we need to add a module first. We will use the module to deploy our master page. For details about the module, see Chapter 11th "Packaging and deployment ". On the Solution tab, right-click custommaster solution and choose add> new item ". Select a module and name it "masterpage ". You can add the master page to the module, but you cannot add a master page to the solution in the new dialog box of Visual Studio.. Net create a master page file, add existing items to the module.
In the Visual Studio file menu, select [file]> [new file], and on the left-side navigation bar, select Web> C #> master page, and click the [open] button, visual Studio creates a new master page, where we can add our own code. In this example, we will copy the tag using the minimal. Master File in Sharepoint. Press Ctrl + S to name the master page customminimal. Master and save it.
If you already have a master page, you can skip this step and go directly to the next step to add the master page to the module. On the Solution page, right-click the masterpage module and choose add> hosts file.
Double-click element. XML in masterpage module to open it in design. As shown in code 10-1, We need to update the element. xml file to deploy the new master page.
We need to add two attributes to the element. xml file to instruct Visual Studio to deploy the master page. The first attribute is the URL with the value "_ catalogs/masterpage". This will deploy customminimal. master to the master page library. You may wonder what is the difference between a list and a database? The answer is no difference. The master page library is a special list for storing master pages. Second, we will delete the URL attribute value "masterpage/" from the file node /". Because if this property value is retained, it creates a folder named masterpage. Finally, we add a type attribute and set the value to "ghosttableinlibrary" so that it is displayed in the view of the master page library. (For more information about module deployment, see Chapter 11th "Packaging Box deployment ")
Right-click the custommaster project and select to deploy the created master page to SharePoint. Because SharePoint does not contain any context information, When Visual Studio tries to verify the master page, you need to ignore the corresponding warning prompt.
Open the SharePoint top-level site, click website operations in the upper left corner, select site settings, and select the master page library in site settings. We often see the deployed customminimal. master page and mv4.master created through SharePoint designer above. 10-13:
We learned what the master page is and how to create and customize the master page, and deliberately did not look at the content and tag of the v4.master master page, because this is beyond the scope of this chapter, if you are interested in creating your own home page from scratch, you can visit msdn through the following link to view the relevant content: http://msdn.microsoft.com/en-us/library/ee539981 (office.14 ). aspx.