This documentation is archived and is not being maintained.

Installing and Using the Custom Web Parts .NET Assembly

Office 2003

There are several advantages to using a custom Project Server Web Part assembly that is developed with the Microsoft .NET framework.

  • The Web Part description (.dwp) file does not need to be modified for use on Microsoft® Office SharePoint™ Portal Server 2003 or on other Windows SharePoint Services computers that are not provisioned by Project Server.
  • The custom Project Server Web Part assembly is easily installable from a download.
  • The Web Part assembly can manage many user-selectable Project Server views with a single .dwp file.
  • You can change or add selections available to the user, and change the text content in the Web Part properties descriptions.
  • You can use the Visual Studio .NET tools to help localize the Web Part resources.
  • You can design the custom Web Part to fit with other Web Parts on a page.

The custom Web Parts assembly provided with the Project Server 2003 Web Parts download (pj11WebParts.exe) provides those advantages over the default Web Parts that are installed with Project Server.

The download includes the PWAWebParts.dll file, which is a custom .NET assembly that manages a set of Microsoft Office Project Web Access views that are similar to the default Project Server Web Parts. You can use the custom assembly provided, or modify the source code and create a version of the assembly that provides any Project Web Access view you want. For a list of all of the files in the download, see Files in the Project Server Web Parts Download.

This topic includes three sections:

Installing the Custom Web Parts .NET Assembly

The following procedure shows detailed steps for installing the custom Web Parts .NET assembly to a target computer that is running Windows SharePoint Services or SharePoint Portal Server. In summary, you copy the assembly to the target computer, register the assembly in the Global Assembly Cache (GAC), register the assembly as safe in the web.config file, and then create a Web Part description (.DWP) file for the assembly.

  1. Copy the file PWAWebParts.dll assembly in the download to any convenient directory on the target computer. For example, copy the assembly to the following directory (substitute [Inetpub] with the path for your server, which is usually C:\Inetpub):
    [Inetpub]\wwwroot\bin
  2. Open the GAC on the server running Windows SharePoint Services. On the Start menu, click Run, and then type assembly.
  3. Drag the file [Inetpub]\wwwroot\bin\PWAWebParts.dll to the GAC window, and drop it. The following figure shows the assembly is registered as PWAWebParts.

    PWAWebParts assembly registered in the Global Assembly Cache (GAC)

  4. Right-click PWAWebParts in the GAC, click Properties, double-click the value of the Public Key Token, and then copy it to the Clipboard. For example, the previous figure shows the Public Key Token value is dd8403f09dd2b43b
  5. Register the assembly as safe in the web.config file that is associated with the Web site where you plan to use the custom Web Part. There are typically several Web sites on a server. To find the correct web.config file, in the Microsoft Internet Information Services (IIS) Manager, expand the Web Sites node, right-click the Web site you will use, and click the Home Directory tab. You need to modify the web.config file in the directory specified by Local path.

    For example, if Local path is C:\Inetpub\Sample, use Notepad or any text editor to open the file C:\Inetpub\Sample\web.config.

    Note  If you edit the wrong web.config file, IIS does not recognize the assembly as safe on that Web site. If you import and then try to use that Web Part, you would get the following error message:

    A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.

    Create the following child element on one line within the SafeControls element.

    <SafeControl Assembly="PWAWebParts, Version=12.0.0.0, Culture=neutral, PublicKeyToken=" Namespace="PWA" TypeName="*" Safe="True" />

    Then paste the Public Key Token value into the line, as shown in the following example. The SafeControl element and attributes must all be on one line. If there are any newline characters or other variations in the line, you would get the same error message previously described when you try to import the Web Part.

    <SafeControl Assembly="PWAWebParts, Version=12.0.0.0, Culture=neutral, PublicKeyToken=dd8403f09dd2b43b" Namespace="PWA" TypeName="*" Safe="True" />
  6. Create a Web Part description file for PWAWebParts and name it PWAWebParts.dwp. To quickly make the file, copy a sample .dwp file to any convenient place. For example, create a directory named C:\WebParts, and then enter the following commands in a Command Prompt window (change [Program Files] to the value for your Windows SharePoint Services computer):
    cd [Program Files]\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\STS\LISTS\WPLIB\DWP
    copy MSContentEditor.dwp \WebParts\PWAWebParts.dwp
  7. Edit the PWAWebParts.dwp file in Notepad or any text editor as follows.
    <?xml version="1.0" encoding="utf-8" ?>
    <!-- _lcid="1033" _version="11.0.5510" _dal="1" -->
    
    <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
       <Assembly>PWAWebParts, Version=12.0.0.0, Culture=neutral, PublicKeyToken=dd8403f09dd2b43b</Assembly>
       <TypeName>PWA.PWAPart</TypeName>
       <Title>PWA Web Part</Title>
       <Description>Used for viewing PWA information</Description>	
       <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
    </WebPart>
    The TypeName element is the class name of the Web Part assembly in the format namespace.classname. That is, if you open the Microsoft Visual Studio® solution file PWAWebParts.sln in the download and then open the C# file PWAPart.cs in Solution Explorer, you will see the namespace is PWA. The following line in PWAPart.cs shows the class name is PWAPart, and the PWAPart class inherits from the class Microsoft.SharePoint.WebPartPages.WebPart.
       public class PWAPart : Microsoft.SharePoint.WebPartPages.WebPart
    

    Note  The _lcid and _version numbers must match the values for the MSContentEditor.dwp on your server. The Assembly element line must be all on one line, and the values must exactly match the values from the GAC that you entered in the web.config file.

Using the Custom Web Parts .NET Assembly

You can use the Web Part assembly specified in PWAWebParts.dwp just as you use any other Web Part. One of the advantages of the custom assembly is that the computer running Windows SharePoint Services or SharePoint Portal Server does not have to be provisioned by Project Server. You can import PWA Web Part directly into a Web Part Page. You can also add PWA Web Part to a Web Part gallery so that when you click Modify Shared Page or Modify My Page and then click Add a Web Part and Browse, PWA Web Part is available in the gallery.

Instead of importing one of the default Project Server Web Part description files such as PORTVIEW.DWP, you import PWAWebParts.dwp. For more information, see To import the modified Web Parts in Web Parts and SharePoint Portal Server.

When you modify a Web Part Page and drag PWA Web Part onto the page, you see the following statement within the PWA Web Part pane on the page. The words Click Here are a link to the PWAPart properties pane where you can select any one of the six Project Web Access views the Web Part provides, and specify the Project Server URL, project ID, and other properties.

This Project Web Access Web Part has not yet been configured. Please Click Here to display the properties toolpane for this Web Part. You can then select the information you want to view in this Web Part, as well as define the path for the Project Server and the Project ID.

In the following figure, the Title is PWA Web Part, the Height is 4 Inches, the Web Part Type is Project Report, the Project Server URL is http:\\ProjectServer\sample, and the Project ID is 101 (from the Project Server sample database).

PWA Web Part with the PWAPart properties pane for setting the view and Project Server URL

When you click OK or Apply, the Web Part .NET assembly gets the data from Project Server and displays it in the Web Part instance you have specified, as shown in the following figure.

Note  The Web Part title is a concatenation of the Title and the Web Part Type you specified.

PWA Web Part with the PWAPart properties pane for setting the view and Project Server URL

Modifying the Custom Web Parts .NET Assembly

The PWAPart properties pane selections and resources for the drop-down menus are defined in the C# code and PWAPart.cs and PWAPart.resx resource files in the Visual Studio project of the download. You can modify the C# code and resource files with Microsoft Visual Studio .NET, compile your own version of the custom assembly, and then follow the same procedure in this topic to register the assembly on the target computer.

Note  The source files provided in the download require Visual Studio .NET 2003 with the .NET Framework 1.1, or higher.

To change or add to the selection of Project Server Web Parts available in the PWA Web Part pane, modify the RenderWebPart method in the PWAPart class. For example, you could change the SimpleUI URL option of any of the Project Web Access views.

       protected override void RenderWebPart(HtmlTextWriter output)
   {
      switch(_WebPartType)
      {
         case eWebPartType.None:
            output.Write("This Project Web Access Web Part has not yet been configured. " 
               + "Please <a href=\"?ToolPaneView=1&wpid=" 
               + this.StorageKey + "\">Click Here</a> to display the properties " 
					+ "pane for this Web Part. " 
               + "You can then select what information to view in this Web Part, as well as "
               + "define the path for the Project Server and the Project ID.");
            break;
         case eWebPartType.Analyze:
            output.Write("<iframe src=\"" + _sPWAURL 
               + "Views/VisionView.asp?SimpleUI=77&NoSaveLinkBtn=1\" "
					+ "width=100% height=100%></iframe>");
            break;
         // ...
         /* Add or modify case statements */
       
      }
   }
  

You can also modify the list of view names and descriptions in the PWAPart.resx resource file.

Next you create a strongly-named key and set the version number and reference to the key file in AssemblyInfo.cs. For example, in a Visual Studio .NET Command Prompt window, type the following.

    cd C:\WebParts
sn -k WebPartKey.snk
  

In AssemblyInfo.cs, set the reference.

    [assembly: AssemblyKeyFile("c:\\WebParts\\WebPartKey.snk")]
  

In the Visual Studio .NET project, you also need to set a reference to Microsoft.SharePoint.dll, which you can copy from the Windows SharePoint Services target computer if you are not developing directly on the target computer, and then compile the new PWAWebParts.dll.

For more information on developing a custom Web Parts assembly, see the Microsoft SharePoint Products and Technologies 2003 Software Development Kit (SDK).

 



Show: