Title: Utveckling av Web Parts
1Utveckling avWeb Parts
- Per Ahlbergper.ahlberg_at_microsoft.com
- Developer EvangelistMicrosoft AB
2Web Part Framework
- Personalize your SharePoint home page to simplify
and focus on the information that is most
relevant to you. - Authors build custom solutions using Web Parts
and Web Part Pages. - .NET developers extend SharePoint by
encapsulating web services and enterprise data as
Web Parts
3Web Parts
- End-user customizable controls
- Personalization store
- Web part framework now in ASP.NET
- Support for assembly-based ASP.NET 2.0 parts
- WSS Web Parts fully supported
- Improved in V3 User interface for Web Parts
4Portable Web Parts
- Web Part is a .NET web custom control assembly
- DWP files contain meta-data describing the
instance of the part - Code doesnt travel with the part
- Box administrators must install the assembly
5Types Of Web Parts
- WSS Web Parts
- Microsoft.SharePoint.WebPartPages.WebPart
- Client Connections, Caching, Work Items
- Uses XML Serialization
- Hybrid Web Parts
- Microsoft.SharePoint.WebPartPages.WebPart
- Use for Migration
- Uses ASP.NET Serialization
- Direct ASP.NET Web Parts
- Microsoft.Web.UI.WebControls.WebParts.WebPart
6ASP.NET Web Part Connections
- Similar Connection Types
- ICell -gt IField, IList -gt ITable
- Automatic translation from WSS v2 types
- ASP.NET 2.0 adds support
- Custom connection interfaces
- Custom transformers
7Integration Limitations
- Cannot use ASP.NET 2.0 Web Part Pages Not
directly compatible as-is - Pages must include SPWebPartZones and
SPWebPartManager - This is done to automatically handle
compatibility issues - No built-in support for treating .ASCX files
(user controls) as Web Parts - You can use .ASCXs in pages, though
- Wrappers for .ASCXs can and will be created
8DWP Sample
9DWP Sample
10Key Features for Developers
- An extension to the .Net Framework
- Installed when you install WSS v2
- Web Part Pages are ASP.NET pages
- Web Parts are ASP.NET web custom controls
- Scales out for large server farms
- Use Visual Studio to quickly build, test, and
deploy custom Web Parts.
11Web Part Properties
- Base class properties
- Custom Properties
- Default property sheet for browseable properties
with builder infrastructure - Use ToolParts for creating custom property UI
- There are limited types because we are Xml
serializing properties - string, bool, int, float, enum, System.DateTime,
and System.Drawing.KnownColor
12Web Part Properties
Category("Custom Properties") WebPartStorage(St
orage.Shared) FriendlyNameAttribute("Custom
Integer") Description("Type an integer value.")
Browsable(true) XmlElement(ElementName"Super
Int") public int MyInt get return
_myInt set _myInt value
13Web Part Rendering
ASP.NET Page
Web Part Framework
ASP.NET Page
Zone 1
Zone 2
Zone 3
Content DB
Web Custom Controls
14Other Framework Features
- Run-time filter enables the ability to turn parts
on and off - Developers can add and remove Web Part menu items
- Developers can create custom views of the Task
Pane using ToolParts
15Web Part Code Access Security
- Code access security (CAS) allows box
administrators grant specific rights to
assemblies - Goal of CAS is to separate access rights of the
user from the access rights of the assembly - Admin can deny access to local resources for
partial trusted assemblies - Admin can allocate trust based on signatures,
strong names, and certificates
16Security
- Only registered set of web custom controls will
run in SharePoint pages - Inline script in the page will not execute
- Code behind in pages can be made to work
- All executable code (e.g. web custom controls,
web parts, and code-behind classes) needs to be
installed on physical web server
17Web Part Rendering
Control
- System.Web.UI.Control defines Render method
- HtmlTextWriter output stream
- WebPart makes Render final
- Used to render chrome
- Web Part developers override RenderWebPart method
WebPart
Custom Part
18RenderWebPart(HtmlTextWriter)
- Implementation Options
- HtmlTextWriter.Write
- HtmlTextWriter utility methods
- Composite Control tree
- Designer
19Implementation Option 1
protected override void RenderWebPart(HtmlTextWri
ter output) if (Page.Request.Browser.Frames)
output.Write("ltiframe src\"www.microsoft.c
om\" /gt")
20Implementation Option 2
- HtmlTextWriter Utility methods
protected override void RenderWebPart (HtmlTextWr
iter output) if (Page.Request.Browser.Frames)
output.WriteBeginTag("iframe")
output.WriteAttribute("src", Url)
output.Write(HtmlTextWriter.TagRightChar)
output.WriteEndTag("iframe")
21Implementation Option 3
- Composite control
- Override CreateChildControls to build control
tree of Server Controls - Call RenderChildren in RenderWebPart
22Composite Control tree
protected override void CreateChildControls()
_mybutton new HtmlButton()
_mybutton.InnerText "Set Web Part Title"
_mybutton.ServerClick new EventHandler(_mybutt
on_click) Controls.Add (_mybutton) protecte
d override void RenderWebPart (HtmlTextWriter
output) RenderChildren(output)
23Deploy a Web Part
- Assembly located in
- GAC (Global Assembly Cache)
- bin (sub directory under the application root)
- Windows SharePoint Services
- Controls, Namespaces and Assemblies have to
enabled in web.config - Class Resources and dwps deployed to specific
locations
24SafeControls Entries
- Controls that have been enabled for a given
v-server - These are entries in web.config
- One per virtual server
- SafeControl entry specifies
- Assembly
- Namespace
- TypeName
- Safe
25Class Resources
- Resources deployed relative to assembly location
- File System location AppRoot\wpresources\Assem
blyName - URL
- http//ltservergt/wpresources/ltAssemblyNamegt
- File System location
- C\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\wpresources
\AssemblyName - URL
- http//ltservergt/_wpresources/ltAssemblyNamegt
Bin
GAC
26Debugging Web Parts
- The Web Part base class derives from
System.UI.Web.Control - Debugging Web Parts is similar to debugging
ASP.Net Web Controls
27Debugging Web Parts
- System Requirements
- Windows SharePoint Services
- Permissions to Debug the ASP.Net process (local
or remote) - Visual Studio .Net (version 7.0 or 7.1)
28Debugging Web Parts
- Debugging on a local machine
- Set ltcompilation debugtruegt in the web.config
of the virtual server - Enable ASP.Net debugging
- Attach to the w3wp.exe process
- Youre ready to debug
29Debugging Web Parts
- Debugging on a remote machine
- Similar setup steps as debugging a project on a
local machine - Require permissions to debug on the remote
machine - Attach to the remote w3wp.exe process
- Youre ready to debug