Using Web Part Pages


Once the web part is compiled and deployed, it is ready for use in SPS; however, web parts are intended to be added and configured by end users ”not developers. Therefore, the tools to manage web parts are an intrinsic part of SPS and are accessible directly to portal users who have sufficient permissions assigned. These permissions allow users to import web parts directly to a page or add them from a gallery.

Adding Web Parts to a Page

Perhaps the easiest way to add a new web part to a page is to simply import it directly into SPS. If the end user has permission to customize pages, then they may select Modify Shared Page Add Web Parts Import to open the Import pane. From the Import pane, users can browse for web part description files that correspond to the web part they want to upload. Figure 5-5 shows the menu selection required to import a web part.


Figure 5-5: Importing web parts

Once the web part is imported, it appears in the Import pane. Users may then drag the web part out of the pane and drop it in a zone on the page. After it is dropped in a zone, you may configure it by setting the available properties. Importing is a simple way to add new parts, but you can make your new web parts more accessible to end users by creating a gallery for them, which you will learn to do later in the book.

Debugging Web Parts

As with any component, you will undoubtedly need to debug your web parts to get them to function correctly; however, because web parts are late-bound components ”meaning they are added to SPS at runtime ”they cannot be run alone in Visual Studio for testing. Therefore, you will need to hook into SPS to properly debug them. Fortunately, this is a fairly straightforward process.

Before you can begin debugging, you must accomplish all of the steps we discussed earlier to give the web part appropriate permissions. This means that you should ensure that the correct policy file is in use and that the web part is added to the <SafeControls> section of the web.config file. Additionally, you should set the project configuration to Debug and be sure that the output path is set to compile the assembly into the \bin directory. Once this is done, you can set breakpoints in your code.

The best strategy for debugging a web part is to select a site within SPS where you intend to add the web part and hook Visual Studio into that page. Hooking into the page is done from the Property Pages dialog. You then set debugging options by selecting Configuration Properties Debugging in the dialog.

Once the debugging options are set, you must modify the web.config file to allow debugging. This requires you to open the web.config file in Visual Studio and modify the <trust> and <compilation> elements. The first thing to do is to change the active policy from WSS_Minimal to at least WSS_Medium because debugging is not allowed under WSS_Minimal. Then you must modify the <configuration> element to have a debug attribute set to True .

To set up debugging in C#, take these steps:

  1. Open a web part project in Visual Studio .NET.

  2. Set the build configuration to Debug.

  3. Right-click the project in the Solution Explorer and select Properties from the pop-up menu.

  4. In the Property Pages dialog, select Configuration Properties Debugging.

  5. Under Debuggers set Enable ASP.NET debugging to True .

  6. Under Start Action set Debug Mode to URL and click the Apply button.

  7. Set the Start URL to the URL for the SharePoint Services site where you will add the new web part.

  8. In the Property Pages dialog, select Configuration Properties Build.

  9. Set the Output Path to \inetpub\ wwwroot \bin .

  10. Click OK.

  11. Open the c:\inetpub\wwwroot\web.config file in Visual Studio.

  12. In the <system.web> section, modify the <configuration> element as follows :

     <compilation batch="false" debug="true" /> 
  13. Modify the <trust> element as follows:

     <trust level="WSS_Medium" originUrl="" /> 
  14. Save the file and close it.

  15. Select Start Administrative Tools Internet Information Server (IIS) Manager to open the IIS Manager.

  16. In the IIS Manager, right-click SPSPORTAL and select All Tasks Restart IIS.

  17. In the Stop/Start/Restart dialog, click OK to restart IIS and apply the new security policy.

  18. In Visual Studio, set the web part project as the start-up project by right-clicking it in the Solution Explorer and selecting Set As Startup Project from the pop-up menu.

  19. Select Debug Start from the menu to begin debugging.

  20. When the SharePoint Services site appears in the browser, click Edit Page from the Actions list.

  21. Select Modify Shared Page Add Web Parts Import from the menu in the upper-right corner of the page.

  22. In the Import pane, click Browse.

  23. Navigate to the web part description file and click OK.

  24. In the Import pane, click Upload.

  25. Drag the web part into any zone on the page. Your breakpoints should work now.




Microsoft SharePoint[c] Building Office 2003 Solutions
Microsoft SharePoint[c] Building Office 2003 Solutions
ISBN: 1590593383
EAN: N/A
Year: 2006
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net