IntroductionIt seems an odd title for an article, it seems more an evidence of low-budget movie, but everyone speaks of the WebPart and how to create a WebPart, so far so good, but we want to go a little farther on, or start customizing and use the real capacity of Webpart, who has had to perform a WebPart robust and reliable, the simple "Hello World" does not answer: P.
This article has as its objective to help and to enter more deeply in the development of WebParts, take in the most boring and difficult to understand, call the part that the 500 000 articles on how to create a WebPart in Sharepoint .... not explain Set in the new edition of Webpart Properties In developing the Webpart each first tasks to be undertaken is the definition on somebody to save a set of information that will serve to support the development of the WebPart. This information will always be associated with Webpart without loss of information that we have to restart the server or restart the services for IIS.
Properties can be set in several types of variables. To begin to define the necessary properties and draw a set of objects in Webpart to categorize and define its field of action, these areas can we define a
WebBrowsable: The property is visible or not in the edition of WebPart Category: Category which includes the property. FriendlyName: Name of area properties Description: Short description of the utility property
Example of creating property for Text and CheckBox. Property Redirect URL / / Text property
[WebBrowsable (true)]
[Category ("Redirect Url")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Personalizable (PersonalizationScope.Shared)]
[FriendlyName ("Redirect Url OK")]
[Description ("Redirect Url OK")]
public string RedirectURLOK
(
_RedirectURLOK get (return;)
set (_RedirectURLOK = value;)
)
/ / CheckBox Property
[WebBrowsable (true)]
[Category ("Redirect Url")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Personalizable (PersonalizationScope.Shared)]
[FriendlyName ("URL Redirect Active OK")]
[Description ("Enable URL Redirect OK")]public bool ActiveOK
(
_ActiveOK get (return;)set (_ActiveOK = value;)
) The result of our property:Example of creating property for DropDown.
Property Cores "To choose a property from a list of values, we must create an enumerate": / / Property Dropdown
public enum Color
(
yellow = 0,
red,
green);
protected _cor colors;
[WebBrowsable (true)]
[Category ("Colors")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[Personalizable (PersonalizationScope.Shared)]
[FriendlyName ("Choose Color")]
[Description ("Choose Color")]
public Color _Cor
(
_cor get (return;)
set (_cor = value;)
) The result of our propertyDesign Menu Editing WebPart "EditorPart, ToolPart"With the development of Sharepoint with different versions "Wss2.0/Wss3.0" and "SPS2003/MOSS2007 " Control WebPart has been altered to become richer experience for the user.
When they were used in the WebPart "Wss2.0/SPS2003" they had the class "ToolPart"which gave the ability to draw on WebPart controls to help this configuration, this class came from the Subject"System.Web.UI.WebControls.WebParts .WebPart. With the existing WebPart "Wss3.0/MOSS2007" object "System.Web.UI.WebControls.WebParts.WebPart"remained, and another class derived from this type of"Microsoft.SharePoint.WebPartPages.WebPart"where there are new functionality for development assistance including the class "EditorPart.
These classes are quite useful when we design our WebPart controls and procedures for support with very specific functionality, here's an example of how we can call this class. public class CustomWebPart: Microsoft.SharePoint.WebPartPages.WebPart
(
..........
/ / Method to call the Graphic Design Classes "EditorPart"public override EditorPartCollection CreateEditorParts ()
(
List <EditorPart> editorParts <EditorPart> = new List (1);
EditorPart MenuListEditorPart item = new ();
item.ID this.ID + = "_mailEditorPart";
editorParts.Add (item);return new EditorPartCollection (base.CreateEditorParts (), editorParts);
)
/ / Method to call the Graphic Design Classes "ToolPart"public override ToolPart [] GetToolParts ()
(
ToolPart [] = new toolparts ToolPart [3];
WebPartToolPart wptp WebPartToolPart = new ();
CustomPropertyToolPart CustomPropertyToolPart CPTP = new ();
WebToolPart WebToolPart ctp = new ();
toolparts [0] = wptp;
toolparts [1] = CPTP;
toolparts [2] = ctp;
toolparts return;
)
.............
) Methods created with the Class Principal then we can begin to derive. EditorPartGraphic Design from the Top of the WebPart using System;using System.Collections;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;
public class MenuListEditorPart: EditorPart
{protected override void CreateChildControls ()
(
..... Add and Draw checks to Top Issue in WebPart
)
} Image ExampleToolPartGraphic Design from the bottom of the edit mode of the WebPart. using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint;
using System.Drawing;
using Microsoft.SharePoint.WebControls;
WebToolPart class: ToolPart
{
protected override void CreateChildControls ()
(
..... Add and Draw checks to the bottom of the Edit WebPart
)
} Image Example New Options Menu WebPartOne of the great capabilities of WebPart its flexibility and ease in providing information in all forms, as in the Menu WebPart propia. To have an end result like the image attachment, it will be necessary to use the method "WebPartVerbCollection" to create new options for Menu WebPart. Small Sample public override WebPartVerbCollection Verbs
(get(
List <WebPartVerb> <WebPartVerb> verbs = new List ();
WebPartVerb verb1 = new WebPartVerb (this.ID + "_docLibVerb", String.Format ("window.location.href = '(0)'", "http://spupload.codeplex.com"));
verb1.Description = ShortcutDescription;
verb1.Text = verb1.Description;
verb1.ImageUrl = "/ _layouts/images/HTM16.GIF";
verbs.Add (verb1);
WebPartVerbCollection allverbs =new WebPartVerbCollection (base.Verbs, verbs);
allverbs return;
)
)
Refreshthest Property WebPart in codeWhenever you change the properties in code. Cs, the command should be used "this.SetPersonalizationDirty ();" to force the update of our property on the WebPart. Example .......
ActiveOK = true;
this.SetPersonalizationDirty ();
.......... ConclusionI hope these small example can help to develop richer and more "User Friendly" our applications, not everything is simple but the end result will be quite pleasant. Sample Project SourceDownload source files -98 kb |