Web Slice Control adapter for MOSS 2007

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]

Comments

# Web Slices and SharePoint | Coded Style

Tuesday, April 21, 2009 2:59 AM by Web Slices and SharePoint | Coded Style

Pingback from  Web Slices and SharePoint | Coded Style

# Daily Blog Post 04/24/2009 &laquo; Murratore&#8217;s Weblog

Saturday, April 25, 2009 1:45 AM by Daily Blog Post 04/24/2009 « Murratore’s Weblog

Pingback from  Daily Blog Post 04/24/2009 &laquo; Murratore&#8217;s Weblog

# re: Web Slice Control adapter for MOSS 2007

Monday, June 15, 2009 8:30 PM by Gaylen

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?  

# re: Web Slice Control adapter for MOSS 2007

Tuesday, June 16, 2009 9:37 AM by dorong

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

# re: Web Slice Control adapter for MOSS 2007

Thursday, June 18, 2009 12:17 AM by Gaylen

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" ?>

- <!--  Copyright (c) Microsoft Corporation. All rights reserved.

 -->

- <WebPart xmlns="schemas.microsoft.com/.../v2">

 <Assembly>Microsoft.Office.Excel.WebUI, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>

 <TypeName>Microsoft.Office.Excel.WebUI.ExcelWebRenderer</TypeName>

 <Title>Excel Web Access</Title>

 <Description>Use the Excel Web Access to interact with an Excel workbook as a Web page.</Description>

 <FrameType>TitleBarOnly</FrameType>

 <PartImageSmall>/_layouts/images/ewr023.gif</PartImageSmall>

 <PartImageLarge>/_layouts/images/ewr023.gif</PartImageLarge>

 </WebPart>

# re: Web Slice Control adapter for MOSS 2007

Thursday, June 18, 2009 9:21 AM by dorong

Hi,

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

Simply add a "<browser refID="Default">  " at the beginning of the file, and then add your targeted webpart:

 <adapter controlType="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart,Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

            adapterType="Netwise.MOSS.Extensions.ControlAdapters.WebSliceAdapter, Netwise.MOSS.Extensions.ControlAdapters, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d08bf77f3d60265" />

using adapterType and controlType.

# re: Web Slice Control adapter for MOSS 2007

Thursday, June 18, 2009 6:41 PM by Gaylen

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.

   <browser refID="Default">

        <controlAdapters>

       <adapter controlType="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart"

         adapterType="ContosoWebSlice.WebSliceAdapter, WebSliceAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=849cd0757eceeaa5" />

       <adapter controlType="Microsoft.SharePoint.Publishing.WebControls.SummaryLinkWebPart,Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

         adapterType="ContosoWebSlice.WebSliceAdapter, WebSliceAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=849cd0757eceeaa5" />

       <adapter controlType="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart,Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

         adapterType="ContosoWebSlice.WebSliceAdapter, WebSliceAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=849cd0757eceeaa5" />

<adapter ContolType="Microsoft.Office.Excel.WebUI, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"

 adapterType="ContosoWebSlice.WebSliceAdapter, WebSliceAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=849cd0757eceeaa5" />

        </controlAdapters>

   </browser>

# re: Web Slice Control adapter for MOSS 2007

Sunday, June 21, 2009 9:15 AM by dorong

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.

msdn.microsoft.com/.../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.

# re: Web Slice Control adapter for MOSS 2007

Tuesday, June 23, 2009 8:22 AM by Gaylen

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?

# SP & Adapter : utiliser les Web Slices d’IE8 dans MOSS

Friday, July 17, 2009 3:12 PM by The Mit's Blog

En fouillant différentes techniques de surcharge du CQWP pour la suite de post, je suis tombé sur ce

# re: Web Slice Control adapter for MOSS 2007

Sunday, August 09, 2009 2:35 AM by pay day loans edmonton

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

# re: Web Slice Control adapter for MOSS 2007

Friday, October 02, 2009 1:48 AM by payday loans in canada

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

# re: Web Slice Control adapter for MOSS 2007

Saturday, October 10, 2009 10:59 AM by cheap metin2 yang

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

# re: Web Slice Control adapter for MOSS 2007

Tuesday, October 13, 2009 9:15 AM by TRM

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:

<browser refID="Default">

<controlAdapters>

<adapter controlType="Microsoft.SharePoint.WebPartPages.ContentEditorWebPart"

adapterType="Comp.ShareNet.Company.WebSliceAdapter.WebSliceAdapter, Comp.ShareNet.Company.WebSliceAdapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5e735f6c215f956b" />

</controlAdapters>

</browser>

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

# re: Web Slice Control adapter for MOSS 2007

Friday, December 25, 2009 7:36 PM by OJJPYE

Hi! wyspCsbK

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: