Paul Pascha

Als SharePoint Developer bij Wortell houd ik me bezig met het ontwerpen en ontwikkelen van maatwerkoplossingen bovenop het SharePoint platform


Posts by Paul Pascha

SharePont 2010: Sneak Peek videos

Today Microsoft published three videos as a Sneak Peek into SharePoint 2010:

The videos present a broad overview about what SharePoint 2010 will offer. Since I’m primarily a developer I had a very pleasant time watching the developer video. I can’t wait to get my hands on it and to see, hear & feal more about SharePoint 2010 at the SharePoint Conference 2009 in Las Vegas!

Sending an e-mail with SPUtility from a site with anonymous access enabled

When using SPUtility.SendEmail() to send an e-mail message from within a site on which anonymous access is enabled, you have to specify the from address.

The code in the fragment below is executed in the SendEmail method and explains why:

email = messageHeaders["from"];

if (email == null){  email = web.CurrentUser.Email;}else{  email = FoldEmailHeader(email, "from", true);  count--;}

The code listed above is being executed in the SendEmail method (obtained by using Reflector). As you can see, if the “from” address is not in the StringDictionary “messageHeaders”, the from address is being retrieved from web.CurrentUser. Since anonymous access is being used, this will obviously fail.

Group your Validators

When you’re building a WebPart that uses some of the ASP.NET validator controls, make sure you specify a validation group for all of them and for the Control firing the validation (i.e. the Submit button). Also, if you’re using a validation summary specify it’s validation group property too.

If you don’t do this, the validation might be fired by other controls rendered by SharePoint preventing you to navigate away from the page. I just ran into this since I created a new Page in a Publishing site. I added my WebPart to this Page and then I wanted to Publish the page. The “Submit for Approval” control in the “Page Editing Toolbar” fired the validation so I had to fill in all my required fields first in order to be able to enter the approval process.
So, I think it’s a best-practice to always use ValidationGroup inside of WebParts.

HideUnhide: My First JavaScript conflict in SharePoint

It had to happen some day….

In the project we’re currently working on, we have a masterpage with a JavaScript powered menu. In this masterpage, a JavaScript function with the name HideUnhide was defined to toggle the visibility of parts of the menu. 

Everything worked fine until we opened a page containing a webpart rendering a SharePoint DateTimeControl. After some investigation, it appeared that the DateTimeControl is referencing a script file with the name datepicker.js from the \12\TEMPLATE\LAYOUTS folder.
As you’ve probably already guessed it turned out that this script file also defines a function with the name HideUnhide. Renaming our MasterPage function obviously solved the issue.
There are lots of .js files in the 12 hive so there’s always a chance that a javascript function with the same name as the one you’re about to implement already exists. 

Reserved QueryString parameters in SharePoint

While testing one of our webparts, I came across a weird problem in which the page containing the WebPart was not rendering if a QueryString parameter with the name “ID” was specified. Fortunately, Google helped me out listing this blog post in the search results.

As stated in this blog post, you should not use the following QueryString parameter names:
  • FeatureId
  • ListTemplate
  • List
  • ID
  • VersionNo
  • ContentTypeId
  • RootFolder
  • View
  • FolderCTID
  • Mode
  • Type

PostBack problems when downloading files from a SharePoint WebPart

For the project I’m currently working on, I needed to develop a WebPart which provides (among other functionality) a download link to a file stored in the database. I’ve used a LinkButton to render the download link and in it’s Click event I’m retrieving the file from the database and output it to the Response stream like this:

Page.Response.ClearContent();Page.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);Page.Response.ContentType = "application/pdf";Page.Response.AddHeader("Content-Disposition", "attachment; filename=document.pdf");Page.Response.Buffer = true;Page.Response.BinaryWrite(file);Page.Response.End();

Now, when a user clicks the download button, a File Dowload Dialog is displayed in the browser. When this dialog is closed the page is not responding to any click within the webpart’s content that normally would cause a postback to occur. With a little Googling, I found this thread which fully describes the cause of the problem and provides a neat solution.

What if “Datasheet View” does not work in lists and libraries?

I was experiencing problems openening the “Datasheet View” of a SharePoint list. In my case, the issue was that ActiveX components where not allowed to run in the browser due to some security settings. While googling to find this solution I found some other things that might have caused the problem. Here they are:

  • The browser is too old: IE 5.01 with SP2 is required
  • The “Microsoft Office Access Web Datasheet Component” is not installed. This is included in Office 2007 and also available on the Office 2003 installation disc