Sunday, December 07, 2008

SPListItem - SystemUpdate, UpdateOverwriteVersion, Update

If you have ever tried to figure out the various SPListItem Update methods the table below, stolen from this blog, gives you an excellent overview:

MethodbSystem bPreserveItemVersion bNoVersion

Friday, December 05, 2008

SPRequest object was not disposed before the end of this thread

Analysing SharePoint logfiles you might find a lot of Potentially excessive number of SPRequest objects warnings in the logfile.

In order to figure out the reason behind this warning you can add a registry key thereby getting a full stack trace as outlined in this blog.

Saturday, November 22, 2008

Delete a file from SharePoint

Deleting a file from SharePoint should be fairly easy, i.e. invoking the

But when invoking this code from a custom web service I get "access denied" error.

Rather than creating my own web service I investigated using standard SharePoint web services. Files can be deleted using web services - as described in the blog where files are deleted from InfoPath.

This MSDN article also describes how to delete files.

Web services are just so much easier to use :-)

Tuesday, October 28, 2008

Working with SharePoint web services - GetList and GetListAndView

Working with SharePoint web services is a challenge. Especially as it is not as well documented as you could have expected. So I often end up spending lots of time with small details which is mainly due to bad design. Let me give an example. Consider the GetList web service outlined below:

The web service contain one parameter:
Whenever I use this web-service I always forget the it doesn't mean the name of the list, but the title of the list. Such a minor detail leads to waste of time - lot of time. And I'm probably not alone out here.

If you use the listName rather than listTitle you get the brilliant error message:
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

Does anyone know how to retrieve information about a list from it's listName rather than listTitle? As end users can rename lists easily the URL for the list is probably better to use than the name.

Sunday, October 26, 2008

The security validation for this page is invalid

Wonder how to avoid the "The security validation for this page is invalid" error when using the SharePoint API. At least I do.

Fortunately I came across this blog yesterday. Not sure it solves all my problems - but I tried it out and some of the exceptions disappeared. I'll make more research.

Saturday, October 04, 2008

Copying documents between doclibs - including metadata and versions

Moving or copying documents from one area in SharePoint to another is, unfortunately, not as easy as copying documents between folders in Windows Explorer.

Basically - you'll need to write a program to do so.

Luckily this blog descibres how.

Tuesday, September 16, 2008

The document could not be created.

The document could not be craeted. The required application may not be installed properly, or the template for this document library cannot be opened.

The error happens when I try to use a PowerPoint template file from SharePoint, POT.

Ideas very much appreciated.

Sunday, September 14, 2008

Office doesn't behave properly with SharePoint - components missing

Sometimes SharePoint is frustrating as different PC's behave differently, especially when dealing with Office documents. This is due to the fact that Office needs some specific ActiveX components that should normally be installed - but for some strange reason sometimes seems to be missing.

This blog refers to a possible solution.

Check out Microsoft KB 938888.

Monday, September 08, 2008

Office 2007 document upload - files corrupt

Adding a file to SharePoint can be implemented through a web service as described in the note from Microsoft. It works fine - for all types of documents except for Office 2007 documents!

Upload goes fine - but when you try to open the file using Office you get the following errors:

The Office Open XML file cannot be opened because there are problems with the content.


SharePoint seems to have an error when adding documents to the filecollecting using the


function. If you add from a byte-array it simply fails with Office 2007 documents. But if you convert the byte-array into a stream, e.g. by saving the byte-array into a file and loading it into a stream, then it works. It's unclear to me why this error occurs - but Microsoft probably drops a single byte in the byte-scenario - which is critical for Office 2007 documents, but other documents seems to survive.

Input and comments very much appreciated.

Friday, August 29, 2008

Some files can harm your computer. If the file information looks suspicious or you do not fully trust the source, do not open the file.

Creating new document based on SharePoint templates you often get the error:

Some files can harm your computer. If the file information looks suspicious or you do not fully trust the source, do not open the file.

SharePoint uses the ActiveXObject from the browser, SharePoint.OpenDocuments, and invokes the function CreateNewDocument (or CreateNewDocument2 in MOSS 2007) with the location of the template (http://...) and the default save location (set to the current folder).

This blog describes how to fix the issue.

However, this didn't change anything for me. Instead I checked out the htmltransinfo.xml file found in "c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML". Notice HandlerUrl - and also notice that when opening Word documents directly from SharePoint these errors doesn't occur. Didn't change anything either.

Some claims running Office Diagnostics solves the issue - haven't got time to try out this model - yet!

Tried it - no luck :-(

Thursday, August 28, 2008

Application Event Log: Unable to connect publishing custom string handler for output caching.

We often get the following error in the eventlog on the SharePoint IIS Server:
Unable to connect publishing custom string handler for output caching.
It would be excellent to learn how to avoid this issue.

Googling the issue many refers to modifying web.config and either add or remove entries to the httpModule section.

But what works? You tell me.

This blog most likely gives a great explanation of the issue. In SharePoint 2003 you had the concept of managed paths - so if you had other web applications on the server you needed to specify these explicit. In MOSS 2007 this feature is removed from the administration tool - and the above blog indicates that it should be added directly in web.config.

Saturday, August 16, 2008

Create a DOCX programmatically

This blog provides a simple example on how to create an Office 2007 docx document.

Monday, August 11, 2008

Web part import - zoneIndex doesn't work

If you have ever tried to import web parts using SPLimitedWebPartManager AddWebPart you'll notice the zoneIndex parameter.

Unfortunately it turns out that zoneIndex only works if web parts are imported in sequence - so you'll need to make certain import is done in the proper sequence order.

After import zoneIndex cannot be modified programmatically - at least I've not found a way to do this.

Saturday, August 02, 2008

Adding a contenttype to a list using Office

Today I learned that it's possible to add a content type to a list using Word. Facinating feature! It's even possible for users not allowed to administer the list to add a content type.

How is this done.

  • Open a Word dokument from another list with the content type you wish to use

  • Save the Word dokument to the new list

Voila - missing accomplished.

The way Office and SharePoint support this feature is through the ContentTypeId property found in Word as outlined below.

The contenttypeid is a guid: 0x01010E00B369AA1A2937544FB28BC321A473DF5A00BCFEABD7F057124C9046012A9BA89F62.

As SharePoint runs promote/demote document properties the content type id is added to the list. I wonder what happens when documents are sent between organisations - will probably be quite messy!

Wednesday, July 30, 2008

?contents=1 - broken web part

Web Parts are smart - but sometimes SharePoint makes it a little too difficult. You cannot edit the page as it's broken. Simply add ?contents=1 to the URL of the page will help you out. Check out this blog. I'm graceful.

Friday, July 25, 2008

Word did not save the document

Suddenly we consistently got the error "Word did not save the document" trying to create or update document in SharePoint.

We tried to research the problem using Google but didn't really find an answer - something we found quite strange. Then we checked the SharePoint log-files found in
C:\Program Files\Common Files\Microsoft Shared\Web server extensions\12\Logs
and voila, we could locate the issue in the log-file, outlined below:
07/25/2008 11:20:13.31 w3wp.exe (0x1054) 0x1364 Windows SharePoint Services General 72ng Medium RPC method = put document 07/25/2008 11:20:13.31 w3wp.exe (0x1054) 0x1364 Windows SharePoint Services General 72n3 Medium put file doc URL = 07Docs/07-1521/New document.docx 07/25/2008 11:20:13.40 w3wp.exe (0x1054) 0x1364 Windows SharePoint Services Database 6f8g Unexpected Unexpected query execution failure, error code 9002. Additional error information from SQL Server is included below. "The transaction log for database 'INTRANET_Content' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases" Query text (if available): "DECLARE @@S uniqueidentifier; DECLARE @@DocId uniqueidentifier; DECLARE @@Level tinyint; DECLARE @@DocUIVersion int; DECLARE @@DoclibRowId int; DECLARE @@iRet int;DECLARE @DN nvarchar(256); DECLARE @LN nvarchar(128); DECLARE @FU nvarchar(260); SET @@Level=255 SET @@DocUIVersion =1 SET @@DocId='331203E1-CF23-4BE5-A306-B53A7F289DDF' SET @@S='9E4A9A77-CF3E-4881-9E6A-AADF9B17AB86'; EXEC @@DoclibRowId = proc_GenerateNextId 'D44ED427-5B4E-4AE0-AC38-BDDB2E54142E','2E51B790-B64E-43... 07/25/2008 11:20:13.40* w3wp.exe (0x1054) 0x1364 Windows SharePoint Services Database 6f8g Unexpected ...5F-A1F2-253C7ADCD4C4'; SET @DN=N'Sager/07Docs/07-1521'; SET @LN=N'New document.docx';BEGIN TRAN; EXEC @@iRet = proc_AddDocument '9E4A9A77-CF3E-4881-9E6A-AADF9B17AB86','D44ED427-5B4E-4AE0-AC38-BDDB2E54142E',1,NULL,@DN, @LN OUTPUT, @@Level, @@DocUIVersion, @@DocId,'2E51B790-B64E-435F-A1F2-253C7ADCD4C4',@@DoclibRowId,?,?,54317,1274,1,0,332,NULL,NULL,0,2097153,0,0,0,-2,NULL,0,NULL,NULL,NULL,NULL,NULL,? OUTPUT,0,?,? OUTPUT; SET @FU = dbo.fn_GetFullUrl(@DN, @LN); IF @@iRet <> 0 GOTO done; EXEC proc_DirtyDependents @@S,1,@FU;IF @DN IS NULL SET @DN=N'Sager/07Docs/07-1521'; IF @LN IS NULL SET @LN=N'New document.docx'; EXEC @@iRet =proc_AddListItem @WebId='D44ED427-5B4E-4AE0-AC38-BDDB2E54142E',@SiteId='9E4A9A77-CF3E-4881-9E6A-AADF9B17AB86',@ListID='2E51B790-B64E-435F-A1F2-253C7ADCD4C4',@ItemId=@@Do... 07/25/2008 11:20:13.40* w3wp.exe (0x1054) 0x1364 Windows SharePoint Services Database 6f8g Unexpected ...clibRowId,@UIVersion=@@DocUIVersion,@RowOrdinal=0,@DocIdAdded='331203E1-CF23-4BE5-A306-B53A7F289DDF',@Size=0,@ItemName=N'New document.docx',@ItemDirName=@DN OUTPUT,@ItemLeafName=@LN OUTPUT,@ItemDocType=0,@UserId=1,@Level=@@Level, @TimeNow='20080725 09:20:12', @tp_ContentTypeId = ?,@nvarchar1=?,@nvarchar2=?,@nvarchar3=?,@nvarchar7=?,@nvarchar14=?,@nvarchar15=?,@sql_variant1 = 0, @error_sql_variant1 = 3,@tp_ContentType=?,@tp_ModerationStatus=?,@acl=NULL; IF @@iRet<> 0 GOTO done; SELECT @@iRet, @@DoclibRowId; done: IF @@iRet=0 BEGIN COMMIT; EXEC proc_GetLinkInfoSingleDoc @@S,@DN,@LN,@@Level; END ELSE ROLLBACK; SET ?=@@iRet;"

Quite simple really - the log file was full and no disk space available.

Thursday, July 10, 2008

Add a Web Part to SharePoint Page Programmatically

Adding web parts to a page programmatically can be done through the SPLimitedWebPartManager object.

However, if you plan to store you web part's in galleries you need to retrieve them. Web Part Galleries are just traditional SharePoint lists, so you'll need to search through the list, and retrieve the content of the item in order to retrieve the web part xml. SharePoint doesn't offer any special Web Part lists.

The blog describes the model fairly detailled.

Monday, June 02, 2008

Document parsers in SharePoint - Office 2003 and 2007 promote-demote differently

Understanding document property promote-demote logic is quite a challenge - at least to me. I still haven't found the great description of how to do it. Input appreciated.

However, this blog describe the concept of setting up property promote-demote. The DocParse.xml file is quite interesting - as Office 2003 and Office 2007 doesn't behave equally for property promotion-demotion. The reason could be this file - as the "doc" extension is not included, and SharePoint maybe for that reason uses another algoritm, thus leading to another result!

From this blog:

WSS includes built-in document parsers for the following file types:

  • OLE: includes DOC, XLS, PPT, MSG, and PUB file formats
  • Office 2007 XML formats: includes DOCX, DOCM, PPTX, PPTM, XLSX an XLSM file formats
  • XML
  • HTM: includes HTM, HTML, MHT, MHTM, and ASPX file formats

You cannot create a custom document parser for these file types. With the XML parser, you can use content types to specify which document properties you want to map to which content type columns, and where the document properties reside in your XML documents.

Wednesday, May 07, 2008

Connect to Outlook - scripting

Connecting a SharePoint folder can easily be scripted as described in this blog. SharePoint uses its own javascript function, ExportHailStorm, to accomplish this.

The stssync protocol, outlined at msdn, is used to enable the synchronization to happen.

If you click Connect to Outlook as outlined below

Outlook will then display the following menu

Clicking advanced will bring up this menu

Various tools exists to enabel two-way synchronization between SharePoint and your desktop, of which Microsoft provide Groove as a part of Office while Colligo Contributor seems a far better solution as outlined in this blog. Also refer to this blog for relevant information about how to access information in SharePoint from OWA.

function ExportHailStorm(type,weburl,guid,webname,listname,viewurl,passport,listrooturl,folderurl,folderid)

Thursday, April 10, 2008

Google Maps in SQL Server - 2005 and 2008

SQL Server 2008 provides support for storing geographical information in the database with the new database geography. For SQL Server 2005 you can read this blog for more information.

Leveraging Google Maps enable you to build a simple web part which can map the address of a contact to a map in Google. Awesome. AJAX today - maybe jQuery in the near future.

Wednesday, April 02, 2008

ItemAdded - listItem is null

I have reported this issue before but haven't found a solution - yet. However, today I came across this blog describing the same problem in the ItemAdding event - which is expected behavior. Apparently others have had this issue too.

Sunday, March 30, 2008

Change approval status without changing ModifiedBy property on a document

We have created a copy-paste utility for SharePoint 2007 which enables documents to be moved from one place within SharePoint to another.

When we move or copy the file we include properties as well as versions with Createdy, ModifiedBy, TimeCreated and TimeLastModified. Everything works fine except for one issue.

When we publish a document using SPFile.Publish() the ModifiedBy and TimeLastModified are changed - therefore we lose the version history.

Instead we try to fix the issue using the comment field - somehow it solves part of the issue but we would appreciate a better solution.

We have tried changing



oFile.Item.ModerationInformation.Status = SPModerationInformation.Approved

oFile.Item.ModerationInformation.Comment = [comment]


but unfortunately ModerationInformation is not available on the SPFile object.

This blog mention the same issue - without a solution. Ideas appreciated.

As our last resort we're currently investigating creating a stored procedure which modified the SharePoint SQL database behind the scene. We would prefer not using this solution (albeit it works).

Monday, March 24, 2008

One of more field types are not installed properly

If you have ever come across the error One of more field types are not installed properly then you know it isn't easy to fix. If it happens in a query download the U2U CAML Builder as described in the blog.

Unfortunately I get the error when I try to delete the field from SharePoint using oDocLib.Fields.Delete(). Any ideas why this happens would be appreciated.

Fortunately this blog gave me some hints.

Sunday, February 03, 2008

Programmatically adding web parts to pages - audience targeting

For easy deployment of web part pages we have build a tool to add web parts to pages, using the SPLimitedWebPartManager feature.

For some web parts we wish to control audience, and to my luck I came across this page describing how to do this. However, understanding the AuthorizationFilter is a challenge.

Reverse engineering is probably the answer ... will update once I have figured this out.

Friday, January 18, 2008

Avoid checkin when uploading files

When uploading files to SharePoint they sometimes are left in checked out status. If the users don't checkin files after upload, other users cannot see the files.

This can happen even for Document Libraries without versioning - and changing it to avoid checkin is not simple.

You need to ensure at least that:
  • Require documents to be checked out before they can be edited = false
  • No versioning af Document library - probably not required
  • Ensure no mandatory columns exists - or ensure they have default values

Check out this blog for information.

Saturday, January 05, 2008

Copy files between document libraries

If you wish to copy files between SharePoint sites or document libraries you cannot use the built-in function, CopyTo, found in the SPFile object, as this only works within the same document library :-(

Instead, you need to traverse all versions of a document, which raises a critical issue. How to ensure the created, createdby, modified and modifiedby properties to be the same in the new document as in the old.

SPFileCollection contains an Add method to add new files. Unfortunately it doesn't exists with all the parameters needed, i.e. properties as well as created, createdby, modified and modifiedby. This method is missing:
SPFileCollection.Add (String, Byte[], Hashtable, Boolean, SPUser, SPUser, DateTime, DateTime)

As this method doesn't exists you have two options.
  1. Copy document with properties - and fix dates and users manually afterwards
  2. Copy document with dates and users - and fix properties manually afterwards

Both methods raises some issues - as you need to manipulate the SPFile and SPListItem object directly.

Manually manipulating createdby can be done as sketched below:

listitem["Created"] = new DateTime(2006, 11,1);
listitem["Modified"] = new DateTime(2006, 12,1);

as outlined on MSDN. Unfortunately this code doesn't work :-(

Other ideas very much appreciated.

Check out other blogs, such as this. Unfortunately it doesn't addess all the issues.

Hint to a solution?

Various investigations led me to analyzing the properties of the listitem after having added the item. It turns out that:



are not equal! Created_x0020_Date contains the value of li["Created"] whereas SPBuiltInField.Created was the time the document was added to SharePoint.

This is even the case in situations where you use the

SPFileCollection.Add (String, Byte[], SPUser, SPUser, DateTime, DateTime)

which was a surpise to me !