This documentation is archived and is not being maintained.

How to: Export an ASP.NET Web Part and Import it to a Windows SharePoint Services Site

Windows SharePoint Services 3

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

You can reuse ASP.NET Web Parts in your Windows SharePoint Services application by exporting them to create .webpart files, which are XML files that contain property values, state data, and assembly or source file details about your Web Part. Because export functionality is not available by default, you must make some modifications to your Web Part code and your configuration settings.

After you have a .webpart file, you can import it into any Windows SharePoint Services application, and the Web Part is displayed with the Windows SharePoint Services look and feel.

To export an ASP.NET Web Part

  1. In your Web Part code, set the ExportMode property to allow properties to be exported. In the following code, we set the value to All, which allows sensitive properties to be exported.

    this.ExportMode = WebPartExportMode.All;
    
  2. Modify the <system.web> section of the web.config file as follows:

    <system.web>
       <webparts  enableExport="true" />
    <sytem.web>          
    
  3. From the Web Part menu, choose Export to create a .webpart file you can import into a Windows SharePoint Services Web Part Page.

To import a .webpart file into Windows SharePoint Services

  1. Place the assembly for your Web Part in the bin or the global assembly cache.

    If you place your assembly in the global assembly cache, your assembly must be strong named and run with full trust code permissions by default. The Web Part is available to all Web applications.

    If you place your assemblyin the bin, you do not have full trust code permissions when your Web Part executes. Because the permissions for the bin directory are very low by default, you may have to create a new trust policy file for your Web Part (recommended), or raise the trust level in the web.config file (the default is WSS_Minimal).

  2. Add the Web Part to the Safe Controls list in your web.config file, for example:

    <SafeControl 
       Assembly="MyWebPart"
       Namespace="MyWebParts"
       TypeName="*" 
       Safe="True"
    />
    
  3. In Design mode, select Add a web part. At the bottom of the Add Web Parts dialog box, click Advanced Web Part gallery and options.

  4. On the Add Web Parts pane, select Import and then navigate to the .webpart file you created in the preceding procedure.

  5. Click Upload and your Web Part appears in the list of Uploaded Web Parts.

  6. Drag it into a Web Part zone on the page and you should see the same Web Part as on your ASP.NET page, only this time it has standard Windows SharePoint Services chrome.

Show: