IT tutorials
 
Applications Server
 

SharePoint 2010 : Writing a WebPart (part 2) - Configuring the WebPart During Deployment

5/8/2013 7:35:36 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1.1. Configuring the WebPart During Deployment

In the previous example, you just wrote an RSSWebPart and deployed and used it successfully. Using it and configuring it, however, was done by the end user through the browser. Sometimes during deployment, you may also want to add a custom SitePage with WebPartZones on it, configure the WebPart automatically during deployment, and drop it in one of the WebPartZones of the SitePage. I'm going to extend this example next by adding a SitePage that has WebPartZones in it. I will configure this WebPart to the CNN RSS feed instead of my blog, and drop this configured WebPart into one of the WebPartZones on the custom SitePage.

Back in the solution in Visual Studio 2010, add the new SharePoint item, and choose to add a new module called WebPartPage. Rename the sample.txt file to WebPartPage.aspx. Note that the associated element.xml also fixes itself when you renamed the sample.txt. Also, ensure that the RSSWebParts feature includes the WebPartPage module that you just added. Open the WebPartPage.ASPX file, and change it to include the code shown in Listing 5.

Example 5. WebPartPage.aspx Code Containing WebPartZones
<%@ Page language="C#" MasterPageFile="˜masterurl/default.master"
meta:WebPartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document"
Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,
Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <table cellpadding="4" cellspacing="0" border="0" width="100%">
            <tr>
            <td height="100%" width="50%">
            <WebPartPages:WebPartZone runat="server" ID="Left" Title="Left"/>
            </td>
            <td height="100%" width="50%">
            <WebPartPages:WebPartZone runat="server" ID="Right" Title="Right"/>
            </td>
            </tr>
    </table>
</asp:Content>

					  

At this time, if you were to package and deploy the solution, you would get a site page with WebPart zones at http://sp2010/WebPartPages/WebPartPage.aspx. But don't deploy yet! Before you deploy, using a feature receiver, you will preconfigure this WebPartPage to contain an instance of the RSSWebPart displaying top stories from CNN.

To do this, add a feature event receiver to the RSSWebParts feature and add the code shown in Listing 6 to the feature event receiver.

Example 6. Code for the Feature Event Receiver
[Guid("34ed6466-8f0e-4330-b910-5a7c8a7d0feb")]
public class RSSWebPartsEventReceiver : SPFeatureReceiver
{
  public override void FeatureActivated(SPFeatureReceiverProperties properties)
  {
    SPFile file = (properties.Feature.Parent as
SPSite).RootWeb.GetFile("/WebPartPage/WebPartPage.aspx");
    SPLimitedWebPartManager lwpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
    lwpm.AddWebPart(
      new RSSWebPart.RSSWebPart()
      {
        Title = "CNN News",
        RSSUrl = "http://rss.cnn.com/rss/cnn_topstories.rss "
      },
      "Left",
      1);
  }

					  

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
  {
    SPFolder folder = (properties.Feature.Parent as SPSite).RootWeb.GetFolder("/WebPartPage");
    folder.Delete();
  }
}

					  

Now, go ahead and package and deploy the solution one more time. After deployment is completed visit http://sp2010/WebPartPage/WebPartPage.aspx. You should see a CNN News WebPart running, as shown in Figure 11.

Figure 11. A preconfigured webpart deployed

Overall, you were able to configure and deploy a WebPart and add it to a WebPartZone, using a feature receiver.

 
Others
 
- SharePoint 2010 : Writing a WebPart (part 1) - Writing the RSSFeed WebPart
- Microsoft Dynamics CRM 2011 : Reporting with Excel (part 4) - Uploading Excel Reports to the Reports List in Microsoft Dynamics CRM
- Microsoft Dynamics CRM 2011 : Reporting with Excel (part 3) - Exporting Dynamic Data to Excel PivotTables
- Microsoft Dynamics CRM 2011 : Reporting with Excel (part 2) - Exporting Dynamic Data to Excel Worksheets
- Microsoft Dynamics CRM 2011 : Reporting with Excel (part 1) - Exporting Static Data to Excel Worksheets
- Active Directory 2008 : Automating the Creation of User Accounts (part 2) - Importing Users with LDIFDE
- Active Directory 2008 : Automating the Creation of User Accounts (part 1)
- SharePoint 2010 : SharePoint Pages - Deploying Pages
- BizTalk Server 2009 : Advanced Orchestration Concepts - The Cost of Parallel Shapes
- BizTalk Server 2009 : Threading and Persistence
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us