Bart Callaerts

You're damned if you do and you're damned if you don't
Browser specific CSS

For those of you who are wondering if it is possible to create a css seperatly for Firefox and IE : Yes you can. It is possible to create let's say a css for IE and then overwrite the classes when the user is browsing through FF.

Microsoft has provided a thing called Conditional Comments and it works like this :

<link rel="stylesheet" type="text/css" href="../css/CSS_FOR_ALL_BROWSERS.css" />

<![if ! IE]>

<link rel="stylesheet" type="text/css" href="../css/CSS_THAT_OVERWRITES_THE_THINGS_THAT_RENDER_DIFFERENT_IN_OTHER_BROWSERS.css" />

<![endif]>

Here is a link to Microsoft's MSDN page : http://msdn2.microsoft.com/en-us/library/ms537512.aspx

Maybe this can come in handy some day.

greetz, Barre

Customizing the content query webpart : Part 2

In addition to my previous post. I was working on a way to give the announcementslist a better look through the use of the CQWP. Exactly the same thing was already made by someone else, so why invent the same thing twice.

Here is a link to a very understandable article :

http://blogs.msdn.com/ecm/archive/2006/10/25/configuring-and-customizing-the-content-query-web-part.aspx

hope you can use some of this in upcoming projects.

greetz

Customizing the Content Query Webpart
Couple of weeks ago,  a client asked us a question I had no immediate answer for. He wanted documents that were posted on many different sites (which are the departments of the company) to be presented together on the first page of the portal. He also wanted these posted documents to have special metadata that is then shown on the cumulative webpart. Last he wanted complete control on how this posts were presented on the portal home page.

My first guess was the RSS Feed Reader webpart. But trying this out gave some shortcomings.  Mainly because it seems not to work for feeds that need authentication when working with Kerberos Authentication. Sure one could change to Kerberos, but this brings some unexpected behavior in other places.

After a little googling I read about the use of Content Query Webpart (CQWP). This is just what I was looking for. The webpart lets me gather all the post I need based on a Content Type. Gives me the opportunity to create a new look for it and present the information I want. With a bit of Customization I managed to customize it in such a way that it was a perfect match.

How to make it work

Here are the steps to implement this feature.

·         Create a new content type with the necessary metadata.

·         Export the Content Query Webpart and Customize the Common View Fields tag.

·         Customize the Itemstyle.xsl

Create a new Content Type

Creating a new content type isn’t that difficult and is not the core business of this article. You can find a good walk through on the Office Online site of Microsoft. Here is a link :

http://office.microsoft.com/en-us/sharepointtechnology/HA100974931033.aspx

 

 

Export the Content Query Webpart and Customize the Common View Fields tag

Next we will export the Content Query Webpart. Default the CQWP will not load all the metadata of an item. Because we want  to use some extra info like the description, we need to tell de CQWP that it needs to load this extra metadata. This is done in the Common View Fields tag.

<property name="CommonViewFields" type="string">Beschrijving, Text;Afdeling, Choice;File_x0020_Type, Text</property>

 

You can see here that I wanted to load the “Beschrijving”, “Afdeling” and the “File Type”. You notice that the File Type is not just “File Type” but “File_x0020_Type”. This is the internal name. Use this to get the file type. Always use the “ “Name of field”, “Field type”; “ notation. When you are done adding the fields to the CommonViewFields save the xml and import it back into the portal.

Customize the Itemstyle.xsl


Our last step is to customize the Itemstyle.xsl file. This file holds all the default Itemstyles like Bulleted Title and image on right… We now want to add our own style and present the user our extra metadata. You can do this easily with Sharepoint Designer. Log in on the portal and find the Itemstyle.xsl file which resides on Style Library/XSL Style Sheets/Itemstyle.xsl. Open it and copy a template which looks the most like the one you want to create. I’ll post mine here.

Change the “Name” and “match” properties. Then change the template to match your wishes.

<xsl:template name="Metallo" match="Row[@Style='Metallo']" mode="itemstyle">

        <xsl:variable name="SafeLinkUrl">

            <xsl:call-template name="OuterTemplate.GetSafeLink">

                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>

            </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="SafeImageUrl">

            <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">

                <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>

            </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="DisplayTitle">

            <xsl:call-template name="OuterTemplate.GetTitle">

                <xsl:with-param name="Title" select="@Title"/>

                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>

            </xsl:call-template>

        </xsl:variable>

        <xsl:variable name="LinkTarget">

            <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>

        </xsl:variable>

        <div id="linkitem" class="item">

            <xsl:if test="string-length($SafeImageUrl) != 0">

                <div class="image-area-left">

                    <a href="{$SafeLinkUrl}" mce_href="{$SafeLinkUrl}" target="{$LinkTarget}">

                        <img class="image" src="{$SafeImageUrl}" mce_src="{$SafeImageUrl}" alt="{@ImageUrlAltText}" />

                    </a>

                </div>

            </xsl:if>

           

                <table cellpadding="0" cellspacing="0" style="vertical-align:top;">

                                <tr>

                                                <td style="width:20px;vertical-align:top;" rowspan="3">

                                                                <a href="{$SafeLinkUrl}" mce_href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}" >            

                                                                                                                                <img class="image" src="/_layouts/images/ic{@File_x005F_x0020_Type}.gif" mce_src="/_layouts/images/ic{@File_x005F_x0020_Type}.gif" alt="{@ImageUrlAltText}" style="margin-right:10px;"/>

                                                                                                                </a>

                                                                                                </td>

                                                                                                <td style="width:100%;" >

                                                                                                                <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>    

                                                                <a href="{$SafeLinkUrl}" mce_href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">

                                                                                <xsl:value-of select="$DisplayTitle"/>

                                                                </a>

                                                </td>

                                                <td class="ms-vb" rowspan="3" nowrap="nowrap">

                                                                <xsl:value-of select="ddwrt:FormatDateTime(string(@Created) ,1032 ,'dd/MM/yyyy  %H:mm')" />

                                                </td>

                                </tr>

                                <tr><td>by <xsl:value-of select="@Afdeling" /></td></tr>

                                <tr>

                                                <td class="description"><xsl:value-of select="@Beschrijving" /></td>

                                </tr>

 

                </table>

        </div>

    </xsl:template>

 

Save the file back to sharepoint Designer. Don’t forget to publish the changes as they will not be visible in unpublished state. 

The last step is to choose the correct Itemstyle in our imported Content Query Webpart. If you did all thing right, it should work like a charm.

Tips and tricks

I had some tips to make life easier when customizing the QCWP.

1.       Sometimes the fiednames you are adding to the Commonviewfields tag are not always the visible name on the sharepoint site, like the file type for example. Te make sure you use the correct internal name, you can figure this out by looking at the url of the column in the document library.

Go to the document library settings and click one of the columns. In the url you find the correct fieldname to use after “Field=”

For example :

http://company/Afdelingen/_layouts/FldEdit.aspx?List=%7B98ACCD4A%2D4184%2D4AAA%2D9584%2DE71007074B1D%7D&Field=Expiration%5Fx0020%5FDate

2.       You can check which field the QCWP is loading by implementing another ItemStyle.

Add the following itemstyle and use it on the website to see the loaded fields.

<xsl:template name="Metallo_ViewFields" match="Row[@Style='Metallo_ViewFields']" mode="itemstyle">

                <xsl:for-each select="@*">

                P:<xsl:value-of select="name()" />

</xsl:for-each>

 </xsl:template>

This view loops over the field and displays its name.

3.       To format a date field you can use the following method.

<xsl:value-of select="ddwrt:FormatDateTime(string(@Created) ,1032 ,'dd/MM/yyyy  %H:mm')" />

Create a Service Account for an ASP.NET 2.0 Application

Last week we were trying to get an newly created webapplication to work under IIS with more privileges than the Network Service. So I created an new user on the server and added it to the Administrators group. Thought this should work cause an admin can do anything on a server. Setting this account as the identity for the application pool our application was running in, did not bring any joy. The result was a "Service Unavailable" page. After looking in the eventviewer, I figured out that the Administrator account was not working as a service account.

After a little googling, I found an MSDN article that explained how to create a service account. Follow these steps to do the job:

1. Create the account on the server it has to work on.
2. Open a command window and browse to c:/WIndows/Microsoft.Net/Framwork/v2.0.xxxxx
3. Type the following command : aspnet_regiis -ga DomainName\UserName
4. This command grants the application all kinds off ASP.net rights to run as a service. The account is now a membe of the IIS_WPG group.

Now you can use this account to act as a service account. Granting it more privileges gives it endless posibilities.

Here's the link to the article :

http://msdn2.microsoft.com/en-us/library/ms998297.aspx

Cheers !!

Mask edit textBox for ASP.net

Hi,
Some of you might be looking for a good Mask Edit textbox to use in your asp.net application. A good one is the Masked Textbox from Excentrics. This control is free to use and easy to use. Try the demo here to see what i'm talking about.
The package consists of multiple controls, besides the masked edit,  that you can add to your toolbox. I haven't looked at the other controls yet but some of them look usefull to.

Take a look at their website here !

Have fun with it.

PS : To use in .net 2.0, just add the controls to your toolbox by clicking choose item in the toolbow and then browsing to the dll in the package you can download.

Dynamically adding web user controls asp.net 2.0

Dynamically adding controls to the page in asp.net 2.0 is very different to what it was in asp.net 1.1

The technique I'm eplaining here is probably not the best way to do this, but this works good and is one of the suggested techniques on the microsoft forum.

The problem is that u can not use the user controls anymore like we where used to in 1.x. As I comprehended from the forum, there is no dll file to reference to. So without a reference, you cannot create a new control like :

Dim myControl as new MyNewControl()

So, the way I made this possible is to put in a contract file, read an interface. Our control will implement the Interface. At the end you can use the following syntax :

Dim myControl As IControlBase = LoadControl("MyNewControl.ascx")

myControl .DoSomething()
myControl.Language = "nl"

and eventually

PlaceHolder.Controls.Add(myControl )

If you have a better and faster technique, feel free to let me know.

Developing a multilingual search result for SharePoint Portal Server

Hi,

This article describes how to change the search results to support documents in multiple languages.

Suppose you have one document translated into different languages. Now if a person searches for this document in SPS based on a certain keyword he should get it into the search result list. Additionally the user should be able to see in what other languages this document excists as well.

The good part is that this solution is NOT based on the Thesaurius files so it doesn't require any maintenance.

Read this article to check out the solution.

- Bart