WebPartExportMode Enumeration


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Specifies whether all, some, or none of a WebPart control's properties can be exported.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

Public Enumeration WebPartExportMode

Member nameDescription

All of a Web Parts control's properties can be exported.


None of a Web Parts control's properties can be exported.


Only properties of a Web Parts control that have been defined as non-sensitive can be exported.

A value from the WebPartExportMode enumerator can be applied to the ExportMode property to specify which properties from a Web Parts control can be exported. By default, the properties of a WebPart control cannot be exported and the control's ExportMode property is set to None. To enable exporting all properties for the control, set the ExportMode value to All. To export only certain properties while preventing the export of properties that contain sensitive data, you set the property value to NonSensitiveData.

A property can be marked as sensitive through the PersonalizableAttribute attribute.


To enable the export feature for a Web application that includes Web Parts controls, in the Web.config file for your application, you must add an attribute to the <webParts> element within the <system.web> section, as in the following markup.

<webParts enableExport="true">


The following code example demonstrates the use of the ExportMode property. Note that for the export code example to work, you must also update your Web.config file as indicated in the Remarks section.

The first part of this example contains the code for a control named TextDisplayWebPart. This control is the same as the custom control that is found in the Example section of the WebPart class overview, except that it adds a Personalizable attribute to the TextDisplayWebPart.ContentText property so the property can be exported. Note that the attribute declaration includes a value of true for the isSensitive parameter, meaning that the property is marked as sensitive data for export purposes. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. This code example assumes that you compile the source code into an assembly, place it in a Bin subfolder of your Web application, and reference the assembly with a Register directive in your Web page. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.

Imports System
Imports System.Security.Permissions 
Imports System.Web
Imports System.Web.UI.WebControls 
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

<AspNetHostingPermission(SecurityAction.Demand, _ 
  Level := AspNetHostingPermissionLevel.Minimal)> _ 
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
  Level := AspNetHostingPermissionLevel.Minimal)> _ 
Public Class TextDisplayWebPart 
  Inherits WebPart
  Private _contentText As String = Nothing
  Private input As TextBox
  Private DisplayContent As Label 
  Private Const _subTitle as String = "Contoso, Ltd"

  Public Sub New()  
    Me.AllowClose = False 
  End Sub 

  <Personalizable(PersonalizationScope.User, True), _
   WebBrowsable()>  _ 
  Public Property ContentText() As String 
      Return _contentText 
    End Get 
      _contentText = value
    End Set 
  End Property

  Protected Overrides Sub CreateChildControls() 
    DisplayContent = New Label()
    DisplayContent.Text = Me.ContentText
    DisplayContent.BackColor = _
    input = New TextBox() 
    Dim update As New Button()
    update.Text = "Set Label Content" 
    AddHandler update.Click, AddressOf Me.submit_Click
    ChildControlsCreated = True 

  End Sub 

  Private Sub submit_Click(ByVal sender As Object, _
                           ByVal e As EventArgs)  
    ' Update the label string.
    If input.Text <> String.Empty Then
      _contentText = input.Text & "<br />"
      input.Text = String.Empty 
      DisplayContent.Text = Me.ContentText
    End If

  End Sub 

End Class 

End Namespace 

The second part of the example shows how to reference the TextDisplayWebPart control in an ASP.NET Web page. Note that in the declarative markup, the ExportMode property value is set to All, meaning that even properties with sensitive values will be exported.

<%@ page language="VB" %>
<%@ register tagprefix="aspSample" 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
  <form id="Form1" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server" />
      title="Zone 1"
        <parttitlestyle font-bold="true" ForeColor="#3300cc" />
          bordercolor="#81AAF2" />
            title = "Text WebPart" 
    <br />

Load the Web page in a browser, and on the verbs menu of the WebPart control, click the export verb and follow the instructions to export a description file containing the control's state and property data.

.NET Framework
Available since 2.0
Return to top