<
runtime
>
<assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">
<probingprivatePath="mydir;mydir2\bin"/>
</assemblyBinding>
</
runtime
>
|
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyKeyFile("c:\\keypair.snk")]
|
[ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>")] //
注意其中Target的定义与类名相同
public
class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart{
…
}
|
[XmlRoot(Namespace="MyWebParts")]
|
//--------------------------------------------------------------------
// File: SimpleWebPart.cs
//
// Purpose: A sample Web Part that demonstrates how to create a basic
// Web Part.
//--------------------------------------------------------------------
using
System;
using
System.ComponentModel;
using
System.Runtime.InteropServices;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Xml.Serialization;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.WebPartPages;
using
Microsoft.SharePoint.Utilities;
using
System.Web.UI.HtmlControls;
namespace
MyWebParts
{
///<summary>
/// This Web Part changes it's own title and implements a custom property.
///</summary>
[XmlRoot(Namespace="MyWebParts")]
public class SimpleWebPart : WebPart
{
private const string defaultText = "hello";
private string text=defaultText;
// Declare variables for HtmlControls user interface elements.
HtmlButton _mybutton;
HtmlInputText _mytextbox;
// Event handler for _mybutton control that sets the
// Title property to the value in _mytextbox control.
public void _mybutton_click (object sender, EventArgs e)
{
this.Title = _mytextbox.Value;
try
{
this.SaveProperties=true;
}
catch
{
Caption = "Error... Could not save property.";
}
}
// Override the ASP.NET Web.UI.Controls.CreateChildControls
// method to create the objects for the Web Part's controls.
protected override void CreateChildControls ()
{
// Create _mytextbox control.
_mytextbox = new HtmlInputText();
_mytextbox.Value="";
Controls.Add(_mytextbox);
// Create _mybutton control and wire its event handler.
_mybutton = new HtmlButton();
_mybutton.InnerText = "Set Web Part Title";
_mybutton.ServerClick += new EventHandler (_mybutton_click);
Controls.Add (_mybutton);
}
[Browsable(true),Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),Description("Text Property")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
protected override void RenderWebPart(HtmlTextWriter output)
{
RenderChildren(output);
// Securely write out HTML
output.Write("<BR>Text Property: " + SPEncode.HtmlEncode(Text));
}
}
}
|
<
SafeControl
Assembly
="SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def148956c61a16b"
Namespace
="MyWebParts"
TypeName
="*"
Safe
="True"
/>
|
sn.exe -T c:\inetpub\wwwroot\bin\SimpleWebPart.dll
|
<?xml
version
="1.0"?>
<
WebPart
xmlns
="http://schemas.microsoft.com/WebPart/v2">
<Assembly>AssemblyName(with no .dll extension), Version=VersionNumber, Culture=Culture, PublicKeyToken=PublicKeyToken</Assembly>
<TypeName>WebPartNamespace.WebPartClassName</TypeName>
<Title>DefaultWebPartTitle</Title>
<Description>WebPartDescription</Description>
</
WebPart
>
|
[XmlRoot(Namespace="name of namespace")]
|
[AttributeDeclaration1, AttributeDeclaration2,...]
public
PropertyType PropertyVariable
private
PropertyType PrivatePropertyVariable
{
get
{
return
PrivatePropertyVariable;
}
set
{
PrivatePropertyVariable = value;
}
|
Attribute
|
Purpose
|
Browsable
|
Set to
false if you don’t want to display the custom property in the property pane. Also, if you set the
WebPartStorage attribute to
Storage.None, your property won't display in the property pane.
|
Category
|
The title of the section of the property pane that you want created to display the custom property. If you don't specify the
Category attribute or if you specify the
Category attribute as "Default", your custom property is displayed in the
Miscellaneous section of the property pane.
Note
If you specify one of the default categories, such as
Appearance, your
Category attribute setting is ignored, and your property is displayed in the
Miscellaneous section.
|
DefaultValue
|
The default value of the custom property. Specifying the default value minimizes the Web Part's storage requirements by storing the property's value only if it is different from the default.
|
Description
|
The contents of the tool tip that appears when you
pause the mouse pointer over the custom property in the property pane.
|
FriendlyNameAttribute
|
The caption displayed for the custom property in the property pane. If you don't specify this attribute, the actual property name will be displayed in the property pane.
|
ReadOnly
|
Set to
true if you want the custom property to be read-only in the property pane.
|
WebPartStorage
|
Set to
Storage.Shared to display the custom property in the property pane when the user is in shared view of the page. Set to
Storage.Personal to display the custom property in the property pane when the user is in Shared or Personal view of the page. Set to
Storage.None if you don’t want the setting to persist for the custom property. The custom property won’t be displayed in the property pane.
|
HtmlDesignerAttribute
|
Used to associate a property builder with the property.
|
//--------------------------------------------------------------------
// File : WebPartCustomProperties.cs
//
// Purpose : A sample Web Part that implements custom properties
// of the following types: string, bool, int, float, enum,
// System.DateTime, and System.Drawing.KnownColor
//
// After building and installing this Web Part, display
// the property pane to see how the user interface
// for setting their values is rendered.
//---------------------------------------------------------------------
using
System;
using
System.ComponentModel;
using
System.Runtime.InteropServices;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Xml.Serialization;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.WebPartPages;
namespace
WebPartLibrary2
{
///<summary>
/// Summary description for CustomPropertyWebPart.
///</summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:CustomPropertyWebPart runat=server></{0}:CustomPropertyWebPart>"),
XmlRoot(Namespace="WebPartLibrary2")]
public class CustomPropertyWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
const string c_MyStringDefault = "Sample String";
const bool c_MyBoolDefault = false;
const int c_MyIntDefault = 20;
const float c_MyFloatDefault = 33.33f;
public enum myFarmEnum
{
barn=0,
tractor,
hay,
pitchfork
};
protected myFarmEnum _myEnum;
// Private variables
private string _myString;
private bool _myBool;
private int _myInt;
private float _myFloat;
private System.DateTime _myDateTime;
private System.Drawing.KnownColor _myColor =
System.Drawing.KnownColor.Red;
// Constructor
publicCustomPropertyWebPart()
{
// Initialize private variables.
_myString = c_MyStringDefault;
_myBool = c_MyBoolDefault;
_myInt = c_MyIntDefault;
_myFloat = c_MyFloatDefault;
_myEnum = myFarmEnum.hay;
_myDateTime = System.DateTime.Now;
}
// Creates a custom property that is a string.
// This property will be displayed as a text box in the
// property pane.
// Create a custom category in the property sheet.
[Category("Custom Properties")]
// Assign the default value.
[DefaultValue(c_MyStringDefault)]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("Custom String")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Type a string value.")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName="MyString")]
// The accessor for this property.
public string MyString
{
get
{
return _myString;
}
set
{
_myString = value;
}
}
// Creates a custom property that is a Boolean value.
// This property will display as a check box in the
// property pane.
[Category("Custom Properties")]
[DefaultValue(c_MyBoolDefault)]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Custom Boolean")]
[Description("Select to set value to True.")]
[Browsable(true)]
[XmlElement(ElementName="MyBoolean")]
// The accessor for this property.
public bool MyBool
{
get
{
return _myBool;
}
set
{
_myBool = value;
}
}
// Creates a custom property that is an integer.
// This property will display as a text box in the
// property pane.
[Category("Custom Properties")]
[DefaultValue(c_MyIntDefault)]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Custom Integer")]
[Description("Type an integer value.") ]
[Browsable(true)]
[XmlElement(ElementName="MyInt")]
public int MyInt
{
get
{
return _myInt;
}
set
{
_myInt = value;
}
}
// Creates a custom property that is a float.
// This property will display as a text box in the
// property pane.
[Category("Custom Properties")]
[DefaultValue(c_MyFloatDefault)]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Custom Float")]
[Description("Type a floating point value.") ]
[Browsable(true)]
[XmlElement(ElementName="MyFloat")]
public float MyFloat
{
get
{
return _myFloat;
}
set
{
_myFloat = value;
}
}
// Creates a custom property that is a System.DateTime.
// This property will display as a text box in the
// property pane.
[Category("Custom Properties")]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Custom Date Time")]
[Description("Type a DateTime value.")]
[Browsable(true)]
[XmlElement(typeof(System.DateTime))]
public System.DateTime MyDateTime
{
get
{
return _myDateTime;
}
set
{
_myDateTime = value;
}
}
public bool ShouldSerializeMyDateTime()
{
return true;
}
// Creates a custom property that is an enum.
// This property will be displayed as a drop-down list in the
// property pane.
[Category("Custom Properties")]
[DefaultValue(myFarmEnum.hay)]
[WebPartStorage(Storage.Personal)]
[FriendlyName("Custom Enum")]
[Description("Select a value from the dropdown list.")]
[Browsable(true)]
public myFarmEnum MyEnum
{
get
{
return _myEnum;
}
set
{
_myEnum = value;
}
}
// Creates a property that is a known system color.
// This property will be displayed as a drop-down list in the
// property pane.
[Category("Custom Properties")]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Custom Color")]
[Description("Select a color from the dropdown list.")]
[Browsable(true)]
发表评论
最新评论
|
评论