Fixing the Sharepoint RSS Proxy issue in a VMWare environment

June 9th, 2009

I found this to be a total pain to figure out how to fix, but once done, the solution is actually very simple.

My setup:

Most people doing Sharepoint development will be doing so in a proper networked environment (setup by a proper network admin).   In which case this article is unlikely to apply to you and this article, can probably point you in the right direction (hint: you need to set your web.config proxy settings).

I am running a Sharepoint development environment at my house, using VMWare, with a minimal win2k3 setup.  I’m not a server admin and I’m conscious hits to performance so the environment is very lightweight.  No Domain Controller, no Active Directory.  I’m a developer not a sysadmin.

The problem:

Unfortunately, Sharepoint cares not for my developing ways and when I tried adding an RSS webpart to a Sharepoint page got the following on-screen error:

An unexpected error occured processing your request. Check the logs for details and correct the problem.

Crapola.  First I thought dodgy rss.

Nope.

Then I thought, the IIS account doesn’t have web access.

Nope.

So then I looked at the million and one “Sharepoint rss proxy” articles on Google  to no avail.  They all want you to make changes to the defaultProxy entry in your Sharepoint’s web.config.

Nope.

The cause:

For some reason, if you don’t have a proxy setup, Sharepoint throws it’s toys out the pram and won’t work.  It won’t even try to make a network call (I checked using WireShark).  Even when I tried to tell the defaultProxy entry to bypass all addresses, it ignored me.

The solution:

Setup your own proxy.  It’s actually very simple (trust me I hate server admin stuff)

  • disable Windows firewall (should have a firewall on your host anyways)
  • I then followed the instructions on support.microsoft.com as best I could under the “Installing the Routing and Remote Access Service” heading.
  • Then magically my rss webparts worked

Also important is to make sure you use a proper RSSViewer part instead of a RSSAggregatorWebPart (added manually).  The only difference I can see is in the configuration xml, but the latter continued to break even after my changes.

Hopefully this doesn’t up some insane hole in my firewall.

Hope that helps.

March 31 possible Nokia N97 release date

January 10th, 2009

According to play.com, the N97 is due to be released March 31 and looks to be priced at £479.99.  Now, it’s most likely that play.com have merely put down the last date of Q1 in hope that it will arrive by then, but I can live with that.

It’s also good to know the full retail price is £20 less than the 8gb iPhone 3G and £120 less than the 16gb iPhone 3G.

I’m definitely looking forward to seeing this phone.

Update Jan 26: Looks like Nokia has come out and stated that March 31 IS NOT the official release date.

Export a Dataview as part of a Site Template

October 21st, 2008

Out of the box, if you use a list-bound dataview as part of a Sharepoint Site Template, you’ll get a grumpy message when creating a new site

“Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.”

How helpful.

The issue is the dataview has a hard-coded reference to the list guid on the original site. To resolve this, simply wrap curly braces “{” and “}” around all instances of the guid. This tells Sharepoint to refer to the newly created list when deploying the site template.

Granted this seems like a bug, but it works.

There should be 6 or 7 references to the listID in any dataview. Just hunt through the code and you should find it fairly easily.

Music worth listening to

October 14th, 2008

Just heard a great song from the Black Tories called Ghost in the Machine which was played during the into of the most recent podcast from the Canucks Outsider.  You can download it from their website…. and if you like it, buy their album.  One of the best songs I’ve heard all year. 

AJAX-Enabled Web-Parts: solving the problem of changing Client IDs

September 16th, 2008

AJAX-Enabled Web-Parts: solving the problem of changing Client IDs

One of the most challenging aspects of building SharePoint-enabled web parts is using JavaScript to interact with specific controls. As a consequence of how SharePoint renders controls with id’s in Sharepoint WebParts, it’s near impossible to write clean JavaScript.

From a maintenance perspective I HATE using server-side code to render JavaScript. It’s inelegant and reeks of a lack of forethought. Yuck yuck yuck. It’s like sweeping dust under the rug.

Wherever possible, webpart-specific javascript should be held within a single .js file (stored in the 12Hive). The problem is that Sharepoint alters a control’s ID during the page rendering process.

So, a label with the ID “label1” might become “ctl00_label1”. The naming process is entirely unpredictable.

This makes interacting with a specific DIV, INPUT or any other html element very difficult because you can’t predict the rendered IDs during development. This is especially problematic if you’re looking to host several instances of a webpart on a single page.

One really terrible way of dealing with this is to render the html yourself by adding literal controls ala

[code lang='c#']
LiteralControl l = new LiteralControl();
l.text = “

blah

”;
this.Controls.Add(l);
[/code]
This is a terrible approach which is severely limiting and unnecessary.

To tackle the problem I’ve devised the following solution which revolves around creating a Javascript class to accompany the web part:

  • create properties to store the dynamically generated IDs of every html component to wish to interact with
  • create pointers to every html component you wish to interact with
  • create an init function. As input you pass the clientID of the webpart AND the id’s of every component you wish to interact with.
  • this function will store the id’s using the properties
  • this function will also attach the pointers to their respective objects
  • this function should also attach any eventhandlers
  • create any supporting functions (i.e. webservice calls, webservice receivers)

This approach embraces the absence of reliable identification info. It is also sympathetic to having multiple copies of a webpart on the same page.

Here’s what the javascript might look like

[code lang='js']
function UpdatingLabelWebPart()
{
var me = this; //required to reference the object at runtime

this.clientID = null; //ids
this.labelID = null;
this.buttonID = null;

this.label = null; //controls
this.button = null;

this.register = function (clientID, labelID, buttonID)
{
me.clientID = clientID; //init the id
me.labelID = labelID;
me.buttonID = buttonID;

me.attachToButton();
}

this.attachToButton = function()
{
//if the controls haven't loaded yet
if (document.getElementById(me.buttonID) == null || document.getElementById(me.labelID) == null)
{
setTimeout(me.attachToButton, 50);
}
else
{
//register the controls
me.label = document.getElementById(me.labelID);
me.button = document.getElementById(me.buttonID);

//attach any events
button.AttachEvent("click", me.buttonClicked);
}
}

this.buttonClicked = function(sender, args)
{
me.label.innerHTML = "Hello World";
}
}
[/code]

Then in your webpart you write a teeny tiny bit of javascript which you register as a clientscriptblock.
[code lang='c#']
String myScriptBlock = String.Format(@"
var tmp = new UpdatingLabelWebPart();
tmp.register('{0}','{1}','{2}');
", this.clientID
, this.label1.clientID
, this.button1.clientID);

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "UpdatingLabelWebPartJS",myScriptBlock, true);
Page.ClientScript.RegisterClientScriptInclude(GetType(), GetType().ToString(), "_layouts/1033/myJS/UpdatingLabelWebPart.js");
[/code]

This approach lets you have multiple instances of the same AJAX-enabled webpart and saves you the hassle of having to write annoying javascript (having to write me.label is hardly a chore).

‘Webservice’ is undefined effor with ASP.NET AJAX

August 2nd, 2008

I came across an annoying problem when playing with the ASP.NET Ajax extensions earlier today.  I was trying to call a script-enabled web-service but kept getting a javascript error telling me my service was undefined.  It’s been a month or so since I’ve used MS Ajax and needed a refresher.

Some background:

  • My project namespace is ajaxTest
  • My webservice class is helloTest
  • My webservice function is helloWorld

I enabled the web service using the [System.Web.Script.Services.ScriptService()] attribute

I put the script manager code block in place and included a reference to the service.

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
<Services>
<asp:ServiceReference Path=”helloTest.asmx” />
</Services>
</asp:ScriptManager>

I then created some javascript to call the web service

function testScriptService()
{
var tmp = helloTest.helloWorld(onResult, onTimeout, onError);
}

It was at this point I received the “helloTest is undefined” message.

A quick search on google revealed two websites which helped me.  The first had the right answer (in my situation).  Strangely, the second website had a slightly different solution which seems to have helped a number of people, but I was unable to figure out why (I didn’t work for me).

So, the solution that worked:

You need to fully qualify the javascript with the namespace of your webservice.

Namespace.Class.Function >> ajaxTest.helloTest.helloWorld

The solution which didn’t work for me but has worked for others is to use the following structure:

Namespace.Services.Class.Function >> ajaxTest.Services.helloTest.helloWorld

No idea why the difference, but hey.

Credit where credit’s due, thanks to Omen’s blog and Ryan at Solutek.

Wow wow wow

June 13th, 2008

Check this out! Amazing little video (just watch the first minute or so).

A great post on how to use Subversion properly

May 30th, 2008

Bil Simser over at the Fear and Loathing blog has put together a very good tutorial on how to use Subversion properly, including branching and revisions.

He has pictures, and goes very very slowly which is helpful for “one repository, one code base” people like myself.

It’s crystal clear, and if you use Subversion, will actually make it easier for you to use.

Ta Bil

SharePoint 2007 and WSS 3.0 Dispose Patterns by Example

May 26th, 2008
Just came across a very helpful post on Roger Lamb’s Blog which provides a number of examples on how to properly dispose of objects within the Sharepoint object model. One specific piece which was very useful was:

Changing how a web part displays while in edit mode

May 20th, 2008
There are a number of circumstances where you might want a web part to display differently depending upon the display mode of the page.

For example:

  • you might want to provide detailed instructions to the user while in edit mode (or connections mode, etc.);
  • the scriptaculous & prototype libraries conflict with Sharepoint javascript while in edit mode, causing a range of javascript errors;
  • you might want to provide a more rich user interface than Editor parts allow.

To do so, is quite simple in concept, just identify the display mode, and chuck an “if” statement in there. However, it did take me a while to find the right code and I thought it was worth posting about, especially because it can help you give users a more professional & polished interface.

First, where I looked for the display mode. There’s a WebPartManager class which exists, and has a display mode, but it’s tricky to find an instance.

If while inside CreateChildControls or OnPreRender you try:

WebPartDisplayMode currentMode = this.WebPartManager.DisplayMode;

you will get a null pointer exception, because this.WebPartManager == null. I don’t understand why, but it does.

What you need to do is execute the static GetCurrentWebPartManager function on your current page object (found this from a post by Rich from DevAndDesign.com).

WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(this.Page);

if (!wpm.DisplayMode.AllowPageDesign)
{
this.Controls.Add(new Literal(”browse mode”));
}
else
{
this.Controls.Add(new Literal(”not browse mode”));
}

This relies on the boolean AllowPageDesign property. If true, the page is in edit mode (that includes the edit, connect, design & catalog modes). It’s definitely a bit silly that this.WebPartManager doesn’t work, especially because it’s such a simple property to implement. Maybe somebody can fill me in on the history?