Writing to the SharePoint 2010 ULS

ULS stands for Unified Logging Systems, and it is a SharePoint component that produces log files under the 14 folder. A very easy way to read it is to use some of the tools presented in my previous blog post SharePoint ULS viewers. Btw, at least and according to me, the best one is still the Microsoft ULS Viewer.

The good news is that custom code can write to the ULS too, so in this way it is possible to have a single point of tracing.

In the Microsoft article Trace Log Example you can find an example of a custom tracer.

And in the post Logging to ULS in SharePoint 2010 is it possible to find a custom LoggingService writing the name of the tracing application.

Considerations developing SharePoint 2010 client applications

Here are a few considerations developing client applications accessing the SharePoint 2010 object model:

  • the target processor must be x64 (the default is x86 instead);
  • you need to use .NET framework 3.5 and not 4.0.

As noted in the post SP2010: SharePoint not supported with .NET framework version, these bugs were present since the beta of SharePoint, but they haven't been fixed yet.

SharePoint 2010: extending existing web-parts

In SharePoint 2010, if you need to extend the existing web-parts, you need to create, from Visual Studio 2010, an empty SharePoint project, then add a web-part.

After buid and deploy, you could get an error saying that it's impossible to launch the new web-part.

In this case, the problem is that you need to delete the .webpart file from your project, and add a new .dwp file, witch is essentially the same as the .webpart, but in another xml schema.

You can read more details in the article Extend the Search Box web part in SharePoint 2010.

SharePoint 2010 development: how reference a dll in your wsp

In Visual Studio 2010, you don't need to use WSPBuilder anymore, because there are native SharePoint 2010 project templates.

But how can you add a class library to your solution, and have it referenced and above all included in your wsp package?

Open the Package Designer, go to the Advanced tab, Add, an Assembly from Project Output and select your utility project.

More details in the article How to: Add and Remove Additional Assemblies.

SPQuery issues

If your SPQuery is returning all elements of a list, and not only the filtered ones, probably your Query contains the <Query> begin and end tags: remove them; more details in the post SPQuery returns all items.

Another issue with SPQuery: the SPQuery object is not reusable for multiple queries, so after you use it for a query, if you need to change the Query property, you need to create another SPQuery instance.

SharePoint 2007: how reproduce the Edit With command

Writing your own web parts, it may be possibile to reproduce the Edit with Word/Excel/... command; in fact, this command check-outs the document, then allows it to edit/read it from the office application.

The trick is to use the editDocumentWithProgID2 javascript function; here is an example call:

editDocumentWithProgID2('http://mywebserver/mysiteurl/myDoc.doc', '', 'SharePoint.OpenDocuments', '0', 'http://mywebserver/mysiteurl', 0);

You can read the following very detailed and intresting post: How to open SharePoint documents in Edit mode with Internet Explorer 6 and Windows XP (without regfix).

A few notes:

  • calling this command forces the refresh of the page. If you want to avoid it, you can set the g_varSkipRefreshOnFocus javascript function to true, as described in this question page: editDocumentWithProgID2 issue;
  • if you handle non Office documents (for example: pdf), you can't call this method, and you have to revert to the link allowing the document to open.

Error while saving Office 2003 files from SharePoint 2007

If you get a JavaScript error while saving Office 2003 files from SharePoint 2007, in particular while you are compiling the metadata in the web page that appears after the save dialog, you need to apply the following hot-fixes to your servers: