Wednesday, February 18, 2009

Show document icon using XSL and DDWRT


When displaying a document icon using XSL you may have tried to just map the image from the /_layouts/images folder using the file extension. This will work in most cases but it will not map PDF files etc. unless you add the images or edit the file mappings.

The ddwrt library has just this function made for you:

include a reference to the library in your xslt:

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

This is a snippet that includes the icon and sets the correct icon if the “file” is a folder:

<a href="{@FileRef}">
<xsl:choose>
<xsl:when test="@FSObjType=1"> <!-- Folder -->
<img alt="{@Title}" src="/_layouts/images/folder.gif" style="vertical-align: middle;border:none;"/>
</xsl:when>
<xsl:otherwise>
<img alt="{@Title}" src="/_layouts/images/{ddwrt:MapToIcon('', string(@File_x0020_Type))}" style="vertical-align: middle;border:none;"/>
</xsl:otherwise>
</xsl:choose>
</a>




Folders presented in xsl 

Tuesday, February 10, 2009

Error saving files in SharePoint

When uploading a file to SharePoint a message like “Unable to complete this operation. Please contact your administrator. at Microsoft.SharePoint.Library.SPRequestInternalClass.PutFile(String bstrUrl…” is presented.

The first thought that comes into mind is file size, illegal file types or rights.

But in this case the problem was 0 kb. free on the database server data disk!

So keep in mind that this message can indicate a problem with the space allocated to the Content database, and not necessarily a problem with the configuration.

The problem was solved by detaching the content database, moving it to another disk, truncating the log and attaching it again.

Note: This problem should have been avoided by monitoring disk- or database space.

Thursday, February 5, 2009

String.EndsWith and String.Empty

During a debugging session trying to find out why my a simple test to check a email address against a domain failed I discovered that String.EndsWith will return true if you try to compare a string and a empty string.

In my case I was checking list items with the format @domain.com against a valid e-mail address. But the function always returned the default choice. A “Please Choose” item with no domain configured. (A empty string)

In order to fix the problem I just added an if test to see if the string was empty and then ignored the EndsWith test.

Endswith 

This should have been a regular expression, but it works for now :-)