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);
listitem.UpdateOverwriteVersion();

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:

listitem[SPBuiltInFieldId.Created]

listitem[SPBuiltInFieldId.Created_x0020_Date]

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 !

Saturday, December 22, 2007

Google Maps and SharePoint

Exformatics Activity Management facilities geocoded data such as Google Maps. Various type of cases, e.g. equipment issues a Telecom operator, projects at a large building constructor and can all be associated with their longitude and latitude. Thereby you can seach for activities nearly of various types and get them displayed in a Google Map, as outlined below:



This blog describe how to inline a simple Google Map in SharePoint. Check out this link for documentation.

If you wish to learn more don't hesitate to contact me.

Saturday, December 01, 2007

Content By Type Web Part

Ton Stegeman has done it again - a great new web part. Check out this blog for more information.

Sunday, November 18, 2007

Large content databases - added indexes for performance improvements

Everyone that has inspected SharePoint's content database will notice that all lists and documents are stored in two tables only, AllUserData and AllDocs.

As only a few properties are contained in indexes searches will most likely lead to table-scans. Having a few 1.000 documents in SharePoint might not lead to slow performance but if you're looking at 100.000+ documents the situation is obviously different as outlined in this excellent article.

Thursday, November 08, 2007

Potentially excessive number of SPRequest objects currently unreleased on thread

Hopefully you'll never come across the error "Potentially excessive number of SPRequest objects (35) currently unreleased on thread 5". It seems it can occur in several situations due to issues in your code as well as due to issues within Microsoft Office SharePoint Server 2007.

In order to avoid the problem in your code ensure to properly dispose the SPWeb object as outlined in this Microsoft article as well as in this blog. One important thing missing is the SPWeb.Webs() object - if using this object you also need to dispose all webs within the collection.

Potential reasons include:

Friday, November 02, 2007

SharePoint Content Database

In case you wish to modify the SharePoint Content Database through SQL rather than using Microsoft SharePoint API you might wish to start reading this blog.



Where is my content type used

If you have worked extensively with MOSS content types you have been in situations where you couldn't locate where the content type was used. Thanks for this blog you can now use the SQL below to retrieve that information.

DECLARE @ContentTypeName nvarchar(128)
SET @ContentTypeName='Document'
SELECT w.Title AS [Web Site], w.FullUrl AS [Web Url], al.tp_Title AS [List Title], ct2.* FROM ContentTypes ct1 JOIN ContentTypes ct2 ON LEFT(ct2.ContentTypeId, Len(ct1.ContentTypeId))=ct1.ContentTypeId LEFT OUTER JOIN dbo.ContentTypeUsage ctu ON LEFT(ctu.ContentTypeId, Len(ct2.ContentTypeId)) = ct2.ContentTypeId LEFT OUTER JOIN dbo.AllLists al ON ctu.ListId = al.tp_Id AND ctu.WebId=al.tp_WebId LEFT OUTER JOIN dbo.Webs w ON al.tp_WebId = w.Id WHERE ct1.ResourceDir=@ContentTypeName

Monday, October 22, 2007

SharePoint AJAX Toolkit

If you haven't yet noticed it you need to check out SharePoint AJAX Toolkit. Or even better - start looking for jQuery support for SharePoint. I wonder if Microsoft will support jQuery in a future version of SharePoint. Woud be great.

Sunday, October 21, 2007

AJAX on SharePoint - how to get started

This blog described how to get started with AJAX on SharePoint

Friday, September 28, 2007

Web Content Management Content Type IDs

Check out this blog for a great overview of SharePoint content types.

Saturday, September 08, 2007

ASP.NET or SharePoint --> and SharePoint

Check out this article describing the relationship between ASP.net and SharePoint.

Tuesday, August 21, 2007

SPFileCollection.Add ignores title property on upload

Using SPFileCollection.Add (String, Byte[], Hashtable) as described on MSDN I found that it's simply isn't working properly :-(

Adding system properties doesn't work:

dim oHash as new hashtable
oHash.add("DocumentType","Contract")
oHash.add("Title","Leasing agreement with Smart Leasing Inc.")
oFile = oFolder.Files.Add(,,oHash)

oFile.Item("Title") is not equal to "Leasing agreement...".

The only way is to modify it manually after having added the file, e.g.
dim li as SPListItem
li = oFile.Item
li("Title")="Leasing agreement..."
li.UpdateOverwriteVersion(); ' In order to avoid creating a new version

Any explanations why "Title" property cannot be set in oHash would be appreciated.

Other problems with Add has been reported various places. This blog is worth reading.

Wednesday, August 08, 2007

SharePoint explorer view - cut-paste issues

Using SharePoint "explorer view" provides end-users with the old Windows Explorer view to files which is great.

However, in a few situations the "explorer view" behaves quite strange.

If you try using Cut-Paste the file is moved from one place to another - including all the history, old versions etc. This is great. However - the Cut-Paste does not respect event handlers that are operational.

I have an ItemDeleting events that blocks deleting documents from certain document libraries. It works fine from all interfaces (Word, SharePoint, Web Dav) - except from cut-paste. Obviously Microsoft had to implement custom code to handle the clipboard in this situation - and it seems that they forgot to respect the event handlers. Just too bad.

Any experience with similar issues much appreciated - as well as workarounds.

Saturday, July 28, 2007

MOSS 2007 ActiveX contols

Check out this blog for details.

Wednesday, July 25, 2007

Great workflow tutorial - expense reporting

Creating a custom SharePoint workflow isn't as easy as you might expect. However, a great tutorial can be found here.

Wednesday, July 18, 2007

Monday, July 09, 2007

Managing Active Directory - SharePoint

Managing Active Directory is a challenge especially as only a few applications can act as a true LDAP client.

Extending Active Directory with custom schemas is an excellent model for applications that can act as an LDAP client (e.q. Exformatics ESDH). This allows custom application attributes to be stored in Active Directory, thus maintaining one single point of administration for Users and Computers in organisations.

One of the challenges is that the standard Windows Users, Groups and Computers view doesn't allow for management of custom attributes. ADSI Edit is the answer. Read more here.