Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Parts Overview Web parts in SharePoint 2007 “Hello World” web part Typical deployment.

Similar presentations


Presentation on theme: "Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Parts Overview Web parts in SharePoint 2007 “Hello World” web part Typical deployment."— Presentation transcript:

1 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Parts Overview Web parts in SharePoint 2007 “Hello World” web part Typical deployment in development environment Properties Using user controls in a web part Security Production deployment

2 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Parts Overview Web parts in SharePoint 2007 are using ASP.NET 2.0 web part technology. Although SharePoint 2007 still supports 2003 web parts, any current or future development should be done using ASP.NET 2.0 web parts.

3 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Part Page Structure Web Part Page inherits from SharePoint Web Part Page class and usually has the following components WebPartManager - manages all WebParts; has no user interface. WebPartZone - a container for web parts; provides a layout. WebPart - any control that extends WebPart class CatalogZone - a container for CatalogPart controls. CatalogPart - presents web parts available for addition to the page. EditorZone - a container for EditorPart controls. EditorPart - a control that allows modification to web part properties.

4 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Typical Development Process Create a new web control project that will contain classes that inherit from web parts Specify the project output to bin folder of a specific web application Register the assembly as safe within the web application Use the web part gallery on a site to make the web part available to be used on pages and add the web part to the page Make changes to the web part code, build the project, and test changes.

5 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Simple Web Part SayHello.cs is the c# code file for the web part class AssemblyInfo.cs file specifies version and other information to be used in a strong name References contains a reference to Microsoft.SharePoint dll and to System.Web Install web part templates in Visual Studio.NET (This will not be available until final release) Start a “web control library” project

6 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Hello Word Web Part using System.Web.UI; using System.Web.UI.WebControls.WebParts; namespace HelloWorld { public class SayHello : WebPart { protected override void RenderContents(HtmlTextWriter output) { output.Write("Hello there"); }

7 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Changing Project Properties Change the project build properties to output assembly to bin folder of a web application root. (drive:\Inetpub\wwroot\wss\VirtualDirectories\ \bin) Deployment to web application bin folder simplifies the debugging process in comparison to GAC deployment which requires iisreset. Optionally: Change the project signing properties to sign the assemby which will give an assembly a strong name HelloWorld, Version=1.0.0.0,Culture=Neutral,PublicKeyToken=894812d009aa4cc94

8 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Change web.config in a Web Application Change to web.config of a web application to register the assembly in section Change the trust level to Full to lift security restrictions since the assembly is not in GAC (Alternatively, create a custom policy file, to be covered later)

9 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Add Web Part to a Web Part Page A web part deployed to a web application and registered as safe is available for addition into a web part gallery (there is only one web part gallery per site collection). Using a new button, administrator or developer can add the web part. Once in a web part gallery, add the web part to any web part page in the site collection.

10 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Demo: Basic Web Part Development 1.Create a web control project 2.Create a web part class 3.Change the project build and sign properties 4.Change the web.config of a web application 5.Add web part to the page

11 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Lab: Exercises 1-3 Perform exercises 1-3 from Web Part Development Lab

12 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Part Properties Properties persist web part metadata information in the database either for all users or on per user basis. Base Class Properties – control appearance and behavior (height, width, etc) Custom properties – additional properties required to enhance web part functionality private string message; [Personalizable(), WebBrowsable(true), WebDisplayName("Message"), Category("Custom")] public string Message { get { return message; } set { message = value; } }

13 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Demo: Web Part Properties 1.Web Part Properties 2.Editor Controls

14 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. CreateChildControls Instead of overriding RenderContent all user interface elements can be created in CreateChildControls. TextBox txtBox; Button btn; Label lbl; protected override void CreateChildControls() { base.CreateChildControls(); txtBox = new TextBox(); Controls.Add(txtBox); btn = new Button(); btn.Text = "Update Message“; btn.Click += new EventHandler(btn_Click); Controls.Add(btn); lbl = new Label(); lbl.Text = "Message is “ ; Controls.Add(lbl); }

15 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Using User Controls in Web Parts Develop user control in _controltemplates or any other virtual directory excluded using “managed” paths. Use user control within a web part protected UserControl time = null; protected override void CreateChildControls() { time = (UserControl)Page.LoadControl("/_controlstemplates/CurrentTime.ascx"); this.Controls.Add(time }

16 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Demo: CreateChildControls and UserControls Demo: Web Parts Functionality 1.Build a web part that only overrides CreateChildControls 2.Build a web part that uses a user control

17 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Lab: Exercise 4 Perform exercise 4 from Web Part Development Lab

18 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Production Deployment Production deployment –Web part dll should be strongly named which gives a web part a unique name so that multiple versions of the DLL can coexist without having to rename the DLL. –Web part dll should be in GAC or have a custom security policy –Web part should packaged in a web part or solution package (to be covered in Feature Development)

19 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Code Security - Permissions ASP.Net has a set of permissions such as –IsolatedStorageFilePermission –messageQueuePermission –OdbcPermission SharePoint adds more permissions –SharePoint Permission - controls rights to access resources used by Windows SharePoint Services such as the object model –WebPart Permission - controls rights to access webpart resources such as connections.

20 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Code Security - Trust Levels ASP.NET defines the following trust levels: Full, High, Medium, Low, Minimal SharePoint adds the following trust levels: –WSS_Minimal - default level for any WSS virtual directory (even if web application has Office Server features on it). –WSS_Medium The above trust levels are defined in wss_minimaltrust.config and wss_mediumtrust.config local drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\config

21 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Custom Policy File There are several ways to give assemblies the correct permissions –Change trust to Full –Install assembly into GAC –Recommended: Create a custom policy file for the assembly Custom policy file will define the permissions necessary for the specific assembly

22 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Demo: Security and Custom Policy Files 1.Examine security settings 2.Build a custom policy file for the assembly

23 Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Enabling Call Stack for Debugging Purposes WSS overrides the CallStack attribute which controls whether a call stack and an exception message are displayed when a system-level exception occur. To enable the CallStack attribute. Find the following element In the Web.config file: and change CallStack=“true”


Download ppt "Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Web Parts Overview Web parts in SharePoint 2007 “Hello World” web part Typical deployment."

Similar presentations


Ads by Google