Web Slice Control adapter for MOSS 2007

18 בינואר 2009

15 תגובות

This post is about enabling web slices on Microsoft Office SharePoint Server 2007.


The following example will demonstrate how to easily implement a simple control adapter which will render the required html code for turning any web part on your server into a live web slice.


First thing I did was creating a class called WebSliceAdapter which inherits from ControlAdpater.



   1: public class WebSliceAdapter : ControlAdapter

ControlAdapter has a single method needs to be overridden:



   1: protected override void Render(HtmlTextWriter writer)
   2: {
   3:     var webpart = Control as WebPart;
   4:     if (webpart != null)
   5:     {
   6:         if (Page.Request.QueryString["sliceitem"] != null && Page.Request.QueryString["sliceitem"].Equals(webpart.ID))
   7:         {
   8:             Page.Response.Clear();
   9:             renderWebSlice(webpart, writer);
  10:             Page.Response.End();
  11:         }
  12:         else
  13:         {
  14:             renderWebSlice(webpart, writer);
  15:         }
  16:     }
  17:     else
  18:     {
  19:         base.Render(writer);
  20:     }
  21: }

(I’m clearing the response and ending it because the webslice is not functioning well for some reason when the html it too large or because of the default  js & css of MOSS. I’m still trying to figure out why and how to overcome this)


The following methods are rendering the required HTML code for the webslice surrounding the web part itself:



   1: private void renderWebSlice(WebPart webpart, HtmlTextWriter writer)
   2: {
   3:     writer.Write(getWebSliceHeader(webpart.ID, webpart.Title, 15));
   4:     base.Render(writer);
   5:     writer.Write("</div></div>");
   6: }


   1: private string getWebSliceHeader(string id,string title,int refreshRate)
   2: {
   3:                  return String.Format(
   4:                     @"<div class='hslice' id='hsliceitem{0}'>
   5:                         <a rel='feedurl' href='?sliceitem={0}'></a>
   6:                         <span style='visibility:hidden;display:none;' class='ttl'>{2}</span>
   7:                         <span class='entry-title' style='visibility:hidden;display:none;'>{1}</span>
   8:                         <div class='entry-content'> ",
   9:                     id, title, refreshRate.ToString());
  10: }

 


 


 


 


getWebSliceHeader gets 3 parameters: id of the webslice, the title to display in the favorites bar and the refreshRate which configures the time in minutes for the webslice to be updated. Every time the content of the webslice will be changed the webslice will appear as bold in the favorites bar indicating the user an update is available.


after signing the assembly and placing it into the GAC all is needed in order to make it work is a small change in the compat.browser file located under App_Browsers folder within the web application:



   1: <browser refID="Default">  
   2:   <controlAdapters>
   3:    <adapter controlType="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart" 
   4:             adapterType="Netwise.MOSS.Extensions.ControlAdapters.WebSliceAdapter, Netwise.MOSS.Extensions.ControlAdapters, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d08bf77f3d60265" />
   5:    <adapter controlType="Microsoft.SharePoint.Publishing.WebControls.SummaryLinkWebPart,Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 
   6:             adapterType="Netwise.MOSS.Extensions.ControlAdapters.WebSliceAdapter, Netwise.MOSS.Extensions.ControlAdapters, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d08bf77f3d60265" />
   7:    <adapter controlType="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart,Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 
   8:             adapterType="Netwise.MOSS.Extensions.ControlAdapters.WebSliceAdapter, Netwise.MOSS.Extensions.ControlAdapters, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d08bf77f3d60265" />
   9:   </controlAdapters>
  10: </browser>

Make sure to use full assembly names for every web part you wish to enable the adapter for. In this example I’m using the ContetEditorWebPart, SummaryLinkWebPart and the ContentByQueryWebPart.


* In this example I’m enabling the adapter for all the browsers but you can / should use IE8 definition only.


** Webslices use a different http header when they update so you might need to add a separate definition as well.


This screen shot is from my MOSS homepage after enabling the adapter. This page contains 1 content query web part for showing me my tasks, a news list and a content editor web part. As you can see I now have 3 webslice feeds which I can see from the top bar and on the page itself:


clip_image002


clip_image002[4]


Adding the content editor web part:


clip_image002[6]


The webslices on the favorites bar:


clip_image002[8]


Viewing the content of the webslice:


clip_image002[10]

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

15 תגובות

  1. Gaylen15 ביוני 2009 ב 20:30

    I'm not a MOSS developer, but it seems as though looks easy enough to implement…maybe I'm dreaming.

    Can you help me understand where this code belongs within the SharePoint site? Is this a Windows Class that I am building in VS2008? If so, then what references should I be including and is all of this code just in this one class?

    הגב
  2. dorong16 ביוני 2009 ב 9:37

    Hi Gaylen,

    The code is compiled as a regular class library and it is not using any MOSS related assemblies.

    The solution is based on ASP.NET control adapters which is not a MOSS unique feature.

    However, the changes in the compat.browser file are "MOSS related" since they are made on the server itself – the file is located inside the App_Browsers folder on the IIS.

    Hope this helps,

    Doron

    הגב
  3. Gaylen18 ביוני 2009 ב 0:17

    I got it working! However, I am unable to add any of my existing web parts to the list in the compat.browser file w/o the site crashing.

    If I wanted to setup a web slice for my Excel web part…wouldn't I simply add another line to the compat.browser file using the Assembly name from below and follow that with the WebSliceAdapter?

    Thanks!

    < ?xml version="1.0" encoding="utf-8" ?>


    Microsoft.Office.Excel.WebUI, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
    Microsoft.Office.Excel.WebUI.ExcelWebRenderer
    Excel Web Access
    Use the Excel Web Access to interact with an Excel workbook as a Web page.
    TitleBarOnly /_layouts/images/ewr023.gif /_layouts/images/ewr023.gif

    הגב
  4. dorong18 ביוני 2009 ב 9:21

    Hi,

    Have you tried adding the definition to the compat.browser the same way I did?

    Simply add a " " at the beginning of the file, and then add your targeted webpart:

    using adapterType and controlType.

    הגב
  5. Gaylen18 ביוני 2009 ב 18:41

    Yep – I have that web part working as a web slice. I just can't get any others working.

    Here's my browswer.compat file…it's the 4th adapter in the list (Excel web part) that crashes the site when I add it.




    הגב
  6. dorong21 ביוני 2009 ב 9:15

    Maybe it's because Microsoft.Office.Excel.WebUI is not a class (control) but a namespace.

    Try use Microsoft.Office.Excel.WebUI.ExcelWebRenderer which is the webpart itself.

    http://msdn.microsoft.com/en-us/library/microsoft.office.excel.webui.excelwebrenderer.aspx

    Let me know if it worked or not because I don't have a moss installation available right now in order to test it.

    הגב
  7. Gaylen23 ביוני 2009 ב 8:22

    Nope – I am stuck in the mud. Here's the error I retrieved out of the App log.

    Could not load type 'Microsoft.Office.Excel.WebUI.ExcelWebRenderer'. (C:\inetpub\wwwroot\wss\VirtualDirectories\intranet80\App_Browsers\compat.browser line 11)

    It seems as though I am just fumbling over the the actual web part names themselves. How do I identify the proper web part names in a MOSS site?

    הגב
  8. pay day loans edmonton9 באוגוסט 2009 ב 2:35

    blogs.microsoft.co.il is very informative. The article is very professionally written. I enjoy reading blogs.microsoft.co.il every day.

    הגב
  9. payday loans in canada2 באוקטובר 2009 ב 1:48

    Thanks for the excellent tutorial. I will refer friends to your site.

    הגב
  10. cheap metin2 yang10 באוקטובר 2009 ב 10:59

    Thanks for the excellent tutorial. I will refer friends to your site.

    הגב
  11. TRM13 באוקטובר 2009 ב 9:15

    Hi Dorong

    When i add the following definition into the compat.browser file, i get the SharePoint error "An unexpected error has occurred.".

    The entry in the compat.browser file looks like:




    The library i made has Comp.ShareNet.Company.WebSliceAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5e735f6c215f956b and the assembly name is Comp.ShareNet.Company.WebSliceAdapter.WebSliceAdapter.
    Do you have any idea what could be wrong?
    Thanks for your help

    הגב
  12. daydayunannip15 במאי 2010 ב 0:17

    thanks! 🙂

    lets write them until the admit it, or stop doing it! i am writing them now!

    🙂

    הגב
  13. icon design22 בספטמבר 2012 ב 10:10

    You have hit the mark. It seems to me it is very excellent thought. Completely with you I will agree.

    P.S. Please review Black Hand Icons from yourmailkept1

    הגב
  14. dpmajrncuhh@gmail.com24 באוקטובר 2012 ב 14:20

    thank you, first I got loosing about instruction of two, in that case it doesn't matter what simple as an alternative as i browse the three instructions, excellent thank you!

    הגב