programming4us
         
 
 
Sharepoint

SharePoint 2010 : Word Automation Services - Demonstration Scenario (part 2) - Customizing the DocumentSetProperties Web Part

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
7/15/2013 9:34:15 PM

2. Customizing the DocumentSetProperties Web Part

Before we can customize the welcome page for our custom document set, we need to build a web part with the following additional features:

  • A Build Sales Proposal button that creates and starts the compilation job

  • A status indicator that shows the progress of the compilation job

  • A link to the compiled output file

Although we could create a separate web part that could be used in conjunction with the built-in DocumentPropertiesWebPart, it wouldn’t be overly useful as a stand-alone component elsewhere. Instead, we’ll create a web part that inherits from the DocumentPropertiesWebPart and adds our required additional functionality.

  1. Using Visual Studio 2010, create a new Empty SharePoint Project named SalesProposalApplication, as shown:

  2. Set the debugging site to be the blank site that we created in the preceding section, and select the Deploy As Farm Solution option. Click Finish to create the project.

  3. After the project has been created, add a new Visual Web Part named SalesProposalPropertiesWebPart.

Visual Web Parts provide a design surface when we’re creating web parts. However, since we’re planning to override a built-in web part that already has its own rendering logic, we need to change some of the generated code for the Visual Web Part.

  1. Add a reference to the Microsoft.Office.DocumentManagement assembly, located in the %SPROOT%isapi folder, to the project.

  2. In the SalesProposalPropertiesWebPart.cs file, add the following code:

    using System.ComponentModel;
    using System.Web.UI;
    using Microsoft.Office.Server.WebControls;
    
    namespace SalesProposalApplication.SalesProposalPropertiesWebPart
    {
      [ToolboxItemAttribute(false)]
      public class SalesProposalPropertiesWebPart : DocumentSetPropertiesWebPart
      {
        // Visual Studio might automatically update
        //this path when you change the Visual Web Part project item.
        private const string _ascxPath =
    @"~/_CONTROLTEMPLATES/SalesProposalApplication/SalesProposalPropertiesWebPart/→
    SalesProposalPropertiesWebPartUserControl.ascx";
    
        protected override void CreateChildControls()
        {
          Control control = this.Page.LoadControl(_ascxPath);
          this.Controls.Add(control);
          base.CreateChildControls();
        }
    
        protected override void RenderWebPart(HtmlTextWriter writer)
        {
          base.RenderWebPart(writer);
          this.Controls[0].RenderControl(writer);
        }
      }
    }
    
    
    					  

Tip

When overriding any built-in SharePoint classes, it can be challenging to work out exactly what you need to do to get the behavior that you expect. In the code snippet, to get our web part to render properly, we explicitly need to render our custom user control by overriding RenderWebPart method. Uncovering details such as this from the documentation is often impossible, and this is where Reflector Pro,  is invaluable.


With our custom user control properly hooked up to our web part, we can implement the rest of our custom logic via the user control.

  1. We’ll make use of Asynchronous JavaScript and XML (AJAX) so that the web part can periodically check on the status of the timer job and redraw the controls. Add an UpdatePanel control to the SalesProposalPropertiesWebPartUserControl.ascx file.

  2. We’ll use an AJAX Timer so that we can automatically refresh the status indicator on our control. Drag the Timer control from the toolbox onto the user control design surface. Name the Timer RefreshTimer and set its Enabled property to False.

  3. From the toolbox, add a Label control, a Hyperlink control, and a Button control to the SalesProposalPropertiesWebPartUserControl.ascx file. Within the UpdatePanel control markup, lay out and rename the controls as follows:

    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <div width="100%">
                <br />
                <asp:Label ID="StatusLabel" runat="server" Text=""></asp:Label>
                <br />
                <asp:HyperLink ID="OutputHyperlink" runat="server">
                     Click here to download a compiled copy</asp:HyperLink>
                <br />
                <asp:Button ID="StartCompilation" OnClick="StartCompilation_Click"
                            runat="server" Text="Start Compilation" />
            </div>
        </ContentTemplate>
        <Triggers>
          <asp:AsyncPostBackTrigger ControlID="RefreshTimer" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Timer runat="server" ID="RefreshTimer" Enabled="False">
    </asp:Timer>
    
    
    					  
  4. In the code-behind file (SalesProposalPropertiesWebPartUserControl.aspx.cs), add the following code:

    public partial class SalesProposalPropertiesWebPartUserControl : UserControl
    {
      protected void Page_Load(object sender, EventArgs e)
      {
        RedrawUI();
      }
    
      private void RedrawUI()
      {
        if (SPContext.Current.ListItem != null)
        {
          string ConversionJobId =
                 SPContext.Current.ListItem.GetFormattedValue("JobId");
    
          if (!string.IsNullOrEmpty(ConversionJobId))
          {
    
            OutputHyperlink.NavigateUrl =
                        SPContext.Current.RootFolderUrl + "/temp.pdf";
    
            SPJobHistory history = (from j in
                              SPFarm.Local.TimerService.JobHistoryEntries
                              where j.JobDefinitionId.ToString() == ConversionJobId
                                    orderby j.StartTime descending
                                    select →
                                   ).FirstOrDefault();
    
          if (history != null)
          {
            StatusLabel.Text = history.Status.ToString();
            if (history.Status == SPRunningJobStatus.Succeeded)
            {
              OutputHyperlink.Visible = true;
              StartCompilation.Enabled = true;
              RefreshTimer.Enabled = false;
            }
            else if (history.Status == SPRunningJobStatus.Failed |
                       history.Status == SPRunningJobStatus.Aborted)
            {
              OutputHyperlink.Visible = false;
              StartCompilation.Enabled = true;
              RefreshTimer.Enabled = false;
            }
            else
            {
              OutputHyperlink.Visible = false;
              StartCompilation.Enabled = false;
              RefreshTimer.Enabled = true;
            }
          }
          else
          {
            StatusLabel.Text = "Processing";
            OutputHyperlink.Visible = false;
            StartCompilation.Enabled = false;
            RefreshTimer.Enabled = true;
          }
        }
      }
      else
      {
        OutputHyperlink.NavigateUrl = "#";
        OutputHyperlink.Visible = true;
        StatusLabel.Text = "My Status";
        StartCompilation.Enabled = false;
      }
    }
    protected void StartCompilation_Click(object sender, EventArgs e)
    {
      throw new NotImplementedException();
    }
    
    
    					  

Before our customized web part can be deployed, we need to make a few changes to the solution. The default packaging mechanisms that are set up in Visual Studio work well for creating web parts that are derived directly from System.Web.UI.WebControls.Webparts. Webpart. However, when creating a web part that’s derived from another base class, we’ll occasionally see an “Incompatible Web Part Markup” error message when we’re trying to use the deployed web part on a page. To resolve this error, we need to use an alternative packaging format.

  1. Rename the SalesProposalPropertiesWebPart.webpart file to SalesProposalPropertiesWebPart.dwp.

  2. Replace the contents with the following XML:

    <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
    <Assembly>
    $SharePoint.Project.AssemblyFullName$
    </Assembly>
      <TypeName>
    SalesProposalApplication.SalesProposalPropertiesWebPart.SalesProposalPropertiesWebPart→
    </TypeName>
      <Title>SalesProposalPropertiesWebPart</Title>
      <Description>Web Part Description</Description>
    </WebPart>
    
    
    					  
  3. So that the renamed file is installed properly, edit the Elements.xml file in the SalesProposalPropertiesWebPart folder as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
      <Module Name="SalesProposalPropertiesWebPart" List="113"
              Url="_catalogs/wp">
        <File Path="SalesProposalPropertiesWebPart\SalesProposalPropertiesWebPart.dwp"
              Url="SalesProposalPropertiesWebPart.dwp"
              Type="GhostableInLibrary" >
          <Property Name="Group" Value="Custom" />
        </File>
      </Module>
    </Elements>	  
Other -----------------
- SharePoint 2010 : Word Automation Services - Creating Conversion Jobs, Checking Status of Conversion Jobs
- SharePoint 2010 : The Client Object Model (part 4) - WebPart Communication Without Postbacks
- SharePoint 2010 : The Client Object Model (part 3) - Writing the JavaScript WebPart
- SharePoint 2010 : The Client Object Model (part 2) - Writing the Silverlight WebPart
- SharePoint 2010 : The Client Object Model (part 1) - Infrastructural Objects, Object Identity
- SharePoint 2010 : Making Enterprise Content Management Work - Records Management (part 2) - Configuring Enterprise Document and Records Management
- SharePoint 2010 : Making Enterprise Content Management Work - Records Management (part 1) - Record Declaration, Information Management Policies
- SharePoint 2010 : Making Enterprise Content Management Work - Document Management (part 3) - Document IDs, Managed Metadata
- SharePoint 2010 : Making Enterprise Content Management Work - Document Management (part 2) - Document Sets
- SharePoint 2010 : Making Enterprise Content Management Work - Document Management (part 1) - Item-level Security, Versioning Settings
- SharePoint 2010 : Setting Lockdown Mode for publishing sites, Configuring Site Collection audit settings, Accessing security policy reports
- SharePoint 2010 : Checking effective permission user interface
- SharePoint 2010 : Adding a user via PowerShell, Delegating PowerShell permissions
- SharePoint Server 2010 Business Intelligence Platform (part 6) - Reporting Services
- SharePoint Server 2010 Business Intelligence Platform (part 5) - PowerPivot
- SharePoint Server 2010 Business Intelligence Platform (part 4) - PerformancePoint Services - Time Intelligence, Decomposition Tree
- SharePoint Server 2010 Business Intelligence Platform (part 3) - PerformancePoint Services - Create a Dashboard
- SharePoint Server 2010 Business Intelligence Platform (part 2) - PerformancePoint Services - Using PerformancePoint Within a Site, Dashboard Designer, PerformancePoint Data Connections
- SharePoint Server 2010 Business Intelligence Platform (part 1) - Business Intelligence Web Parts
- SharePoint 2010 : Writing Workflows with Visual Studio
 
 
 
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
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.