Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

ASP.NET 2.0 Web Part Infrastructure and SharePoint 2007 : Page 6

Find out how to make your Web Parts communicate with each other and share data.


advertisement
Registering the Web Parts
At this point, IIS and ASP.NET 2.0 can understand your Web Parts. But SharePoint 2007 needs one more step. You need to register these Web Parts in the Web Part catalog/gallery for SharePoint. To do so, follow these steps:
  1. Go to the Code Magazine Article site, click Site Actions, and select "Site Settings."
  2. Under Galleries, click "Web Parts."
  3. In the page that opens up, you see a Web Part Gallery that shows you a list of all Web Parts that you can use on this site collection. Go ahead and click "New."
  4.  
    Figure 15: The Web Parts you wrote—ready to be used.
  5. In the page that loads, you'll see a list of Web Parts that IIS and ASP.NET 2.0 have made available for use for SharePoint 2007. Somewhere on the page, you should also see the two Web Parts you wrote. You can see this in Figure 15. Now you can't have two Web Parts with the same file name. So at this point, SharePoint gives you the option of changing the names to something more meaningful—I chose to rename them to OPMLEditor.webpart and RSSRender.webpart. Interestingly, you can also export this Web Part from the pure ASP.NET 2.0 framework written previously and simply use the .webpart file (which is just an XML file) to import a Web Part directly.
  6. Go ahead and select the check boxes next to the two Web Parts you are trying to add, give them meaningful names such as OPMLEditor and RSSRender, and then click the "Populate Gallery" button at the top of the page.
 
Figure 16: Specifying the template for the new Web Part Page being added.
Congratulations, your Web Parts are now ready to use. The next step is to actually use them. You can do this using the following steps:

  1. Go to the home page of the "Code Magazine Article" site, select Site Actions, and then click "Create."
  2. Under Web Pages, click "Web Part Page." Add a new page called "BlogReader.aspx" and choose the "Header, Left Column, Body" layout template as shown in Figure 16. Click "Create."
  3. SharePoint should now take you to the page you just added in edit mode (see Figure 17).
  4. In the "Left Column" WebPartZone, click "Add a WebPart," and choose the OPMLEditor WebPart as shown in Figure 18. Similarly, add the RSSRender WebPart in the "Body" WebPartZone. For good measure, add the "Content Editor Web Part" in the "Header" WebPartZone. This is a Web Part that you didn't write—it came with SharePoint. Your page should now look like Figure 19.
 
Figure 17: A newly added Web Part page.
 
Figure 18: Adding the OPMLEditor WebPart.
 
Figure 19: The page coming together—the necessary Web Parts added.
This is where the fun begins. Note that the Web Parts have an "Edit" button next to their title bars. Click that and choose the "Modify Shared WebPart" menu item for the OPMLEditor WebPart. Voila! You see the very same editor you wrote for your ASP.NET WebPart, now working in SharePoint. Fill in your favorite RSSUrls (see Figure 20). Click "OK" to populate the various RSS feeds in your OPMLEditor WebPart as shown in Figure 21. Similarly, go ahead and edit the Content Editor WebPart and give your page a meaningful title in the rich-text editor.

 
Figure 20: The ASP.NET 2.0 Editor you wrote earlier, working in SharePoint 2007.
 
Figure 21: A few RSS feeds populated—make sure you make a note of these.
The next step is to connect the OPMLEditor WebPart to the RSSRender WebPart. Under the "Edit" menu on either OPMLEditor or RSSRender, there is a "Connections" submenu. If you explore that menu further, you will note that SharePoint 2007 was smart enough to understand that the OPMLEditor WebPart can indeed communicate with the RSSRender WebPart. In doing so, it took into consideration not only the common communication interfaces any Web Part may support, but also the various transformers your site may be using at this time. Go ahead and establish this communication by checking on the RSSRender menu item as shown in Figure 22.
 
Figure 22: Establishing Web Part communication in SharePoint 2007.
 
Figure 23: The BlogReader application running in SharePoint.
Congratulations. You just built a SharePoint blog reader. Click the "Exit edit mode" link at the upper right-hand of your page. Now select one of the blog RSS feed URLs from the left, and you should see the blog content loaded on the right. You can see the final site running in Figure 23.


Now, you may argue that SharePoint lets you create lists—so why did you have to write the OPMLEditor WebPart to begin with? Why couldn't you just have created a list in SharePoint 2007 and used that instead? Well, you absolutely could have done that instead. That is the entire point of SharePoint—it lets you achieve nearly everything without ever happening to open Visual Studio. In fact, SharePoint 2007 actually includes an RSS feed Web Part. You'll find you need to write custom Web Parts only for specific custom scenarios. Not only that, SharePoint 2007 provides many time-saving features: You can make the look and feel be 100 percent branded to your organization needs; you get a massive load of functionality right out of the box; and hackneyed tasks such as security, provisioning sites and pages, establishing workflows, integration with Microsoft Office etc., take almost no effort. In many instances such efforts involve no coding at all. So, for the most part, you are solving the actual problem at hand, rather than the specifics of the platform on which you are building your application. Can you say that about plain vanilla ASP.NET 2.0? Probably not!!

SharePoint 2007 is a huge topic. In this and the previous article, I have barely scratched the surface of SharePoint 2007 by demonstrating ASP.NET 2.0 Web Part framework concepts and applying them to SharePoint. The biggest advantage of SharePoint is developer productivity. SharePoint 2007 is a product that is much more usable than SharePoint 2003, and allows organizations to create final solutions, rather than waste time working on products that will deliver those solutions.

Also, SharePoint 2007 can interlink with existing repositories of data in an organization and present relevant information customized in both content and presentation. It provides a significant advantage to any organization.



Sahil Malik Sahil Malik is a Microsoft MVP, INETA speaker, a .NET author, consultant and trainer, and a well-rounded overweight geek. He has a passion for SharePoint 2007, data access, and application architecture. Sahil loves interacting with fellow geeks in real time. His talks are full of humor and practical nuggets. His talks tend to be highly charged, fast moving, and highly interactive. Be sure to check out his blog.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap