Imtech Random Image and Imtech Site Members (Free Web Parts)

September 4th, 2007 by waldek mastykarz

Imtech Random Image Web Part displays randomly chosen Image. The Web Part takes as parameters URL of the Image Library containing images you would like to display. It is also possible to input multiple URL's separated by comma. Additional parameters you can set are: image width and height, in-line CSS style (like border, etc.), image link (you can make image point to the library where all the images are being shown) and the alternate text.

Imtech Site Members Web Part displays the list of users who belong to the Site's Members Group. As the Web Part produces XML and supports XSL you are free in setting the way the members are presented. Out of the box you get two styles: short (Picture and Preferred Name) and Long (Picture, Preferred Name, E-mail and Mobile Phone). To support setting custom XSL, there is an option to render the output as raw XML so you are able to see what fields there exactly are and how the Web Part expects you to build your XSL.

Both Web Parts are free and you can use them without any restrictions. To make it all easier the Web Parts are stored in a solution with the .webpart files supported. All you need to do is to deploy and install the solution and activate the feature.

Download Imtech.SharePoint.WebParts.wsp (10,1KB)

Imtech Solution Setup (Free SharePoint Tool)

September 4th, 2007 by waldek mastykarz

There has been a bug fixed posted. A new version (1.2.0.0) of Imtech Solution Setup is available

Imtech Solution Setup is a tool that installs and deploys SharePoint 2007 solution files (.wsp). The tool works in two modes: setup and standalone.

The standalone mode is meant for "each day" use: after starting the tool you have to select the .wsp you want to install. Then you have to select the Web Applications where you want to deploy the selected .wsp to and click "Setup".

Imtech Solution Setup

In the setup mode the "Browse…" button is disabled: the .wsp has been passed to the setup tool as a command line argument. All the user has to do is select the deployment target(s) and click "Setup".

Although this tool is not extremely powerful and customizable its light weight and simplicity make it works for me. It turns pretty handy in MSI-kind installers.

Download Imtech Solution Setup v1.1.0.0 (44,5KB)

Imtech Solution Setup v1.1.0.0 is a free tool and you can use it without any restrictions.

Imtech C# String Converter (Free .NET Tool)

August 30th, 2007 by waldek mastykarz

Once in a while you need to paste one of these long strings into your C# code. I've set recently a record by pasting an exported SharePoint 2007 RSS Viewer Web Part: more than 400 lines! If it's only once during the solution development it's doable: you could get it well formatted using some Search and Replace with Regular Expressions. But what if you have to paste a dozen of such strings in your code?

That's when I thought that a tool would make life easier: Imtech C# String Converter. It's all for free so don't hesitate and try it out.

Download: Imtech C# String Converter v1.0.0.0.

Using ~SiteCollection prefix in SharePoint CSS files

August 30th, 2007 by waldek mastykarz

Using CSS files is the recommended way for incorporating the chrome in a SharePoint WCM solution. Among the various definitions of the layout pieces there are also images' references. Each such reference can be defined using an absolute of relative URL. As long as you use images in the same directory as the CSS file there is no problem at all: you can manage all the paths easily by simply using one of the URL kinds. Unfortunately a problem occurs when you would like to use images from other directories for example the PublishingImages folder. They should be referenced via relative URLs. Using absolute URLs results in problems when a Site Collection doesn't reside in the root or /sites directory. Also sharing a CSS file among different Site Collections isn't possible while using PublishingImages folder: there is no simple way to make the images' paths be defined dynamically based on the Site Collection calling the CSS file.

Facing this challenge Erik and I figured out a solution: letting the CSS files be parsed by the ASP.NET handler and making SharePoint webcontrols write correct URLs based on the caller Site Collection. As this approach requires connecting of a file type with the parser it seems convenient to make all the files with .css extensions get parsed by ASP.NET. As there is a big possibility that you may use more than one CSS definition file within a solution it would create quite an overhead. That's why we have decided to define a new file extension for our dynamic CSS: CSSX.

Getting our .cssx files parsed by ASP.NET required two steps: sending a .cssx file to the ASP.NET pageHandler (code 1) and making the page built using the buildProvider (code 2). Below you can see both code snippets added within the web.config of the Web Application:

Code 1: Sending .cssx files to the ASP.NET page handler

<system.web>
  <httpHandlers>
    <add verb="GET" path="*.cssx" type="System.Web.UI.PageHandlerFactory" />
  </httpHandlers>
</system.web>

Code 2: Making the page built using the build provider

<system.web>
  <compilation batch="false" debug="true">
    <buildProviders>
      <add extension=".cssx" type="System.Web.Compilation.PageBuildProvider" />
    </buildProviders>
  </compilation>
</system.web>

Then it came to adjusting our CSSX files to the new situation and make them benefit of the SharePoint webcontrols. On the top of the .cssx file we've added:

<%@ Page Language="C#"%>
<%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Registering the PublishingWebControls tag has granted us access to the $SPUrl prefix which helps creating the Site Collection URLs using ~SiteCollection.

It all worked out pretty well. in Microsoft Internet Explorer. Mozilla Firefox seemed to have problems with parsing the .cssx file. With the FireBug extension I've figured out that it doesn't recognize the .cssx files as CSS. I've fixed it by adding ContentType="text/css" to the Page directive:

<%@ Page Language="C#" ContentType="text/css"%>

Now we could use the solution and refer to all image resources like:

background-image: url("<asp:Literal runat='server' Text='<%$SPUrl:~SiteCollection/SiteCollectionImages/someimage.jpg%>'/>");

SharePoint would take care for the proper URL and the literal would render it in the .cssx file.

Knowing this approach will require adding some information in the web.config file, we've created a separate feature with a custom featurereceiver that would do this task. Later on we've found out that we could use the same feature for adding incorporating some more elements like URL rewriting and captchas. 

To make the feature put these code snippets in the right place we have use the SharePoint Add method of the WebConfigModifications collection. Before we did it we also had to define the XML to be added as an instance of the SPWebConfigModification class.

Code 3: Processing the modifications by the feature

SPWebConfigModification modification = new SPWebConfigModification("add[@path='*.cssx']","configuration/system.web/httpHandlers");
modification.Owner = "FeatureName";
modification.Sequence = 1;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = "<add verb='GET' path='*.cssx' type='System.Web.UI.PageHandlerFactory'/>";
someWebApplication.WebConfigModifications.Add(modification);

modification = new SPWebConfigModification("buildProviders","configuration/system.web/compilation");
modification.Owner = "FeatureName";
modification.Sequence = 2;
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
modification.Value = "<buildProviders><add extension='.cssx' type='System.Web.Compilation.PageBuildProvider'/></buildProviders>";

someWebApplication.WebConfigModifications.Add(modification);

To process the changes we used the ApplyWebConfigModifications():

SPFarm.Local.Services.GetValue<SPWebService>(someWebApplication.Parent.Id).ApplyWebConfigModifications();

Dynamic CAML Query

August 30th, 2007 by waldek mastykarz

In his recent post Robert J Wheeler has presented his way of dealing with building CAML queries dynamically. Here at Imtech ICT Business Solutions we use a slightly different approach.

// initiate query
string whereQry = "<Where>{0}</Where>";

for
(int i = 0; i < qryParams.Count; i++)
{
       // exception for last query parameter: don't add another <And>
       if (i < qryParams.Count – 1)
              whereQry = String.Format(whereQry, "<And>" + qryParams[ i ] + "{0}</And>");
       else
              whereQry = String.Format(whereQry, qryParams[ i ]);
}

// remove the last connector spacer
whereQry = String.Format(whereQry, String.Empty);

qry.Query = "<OrderBy><FieldRef Name='PublishingStartDate' Ascending='False' /></OrderBy>" + whereQry;

The first part is quite the same: we use an ArrayList to store the separate `And' statements. Where the difference is, is the way we put them together. We use the String.Format method to link the separate statement to each other what keeps IMHO the code a bit more readable.

Eventually it's not about whose code is better. It's nice to see that other developers share our point of view on the lack of CAML support and trying to develop our own ways of dealing with it.

Displaying SharePoint Fields in different order than edit fields

August 26th, 2007 by waldek mastykarz

Some of our customers like to have the information displayed in a different way than the order of the fields within the Content Types: there is frankly a difference of the information meaning for their customers (visitors) and the Information Workers within the organization. As SharePoint 2007 ships with the in-place edit possibility it's quite obvious that this is the recommended way to use for managing the data – especially when it comes to Information Workers who not necessarily have to have technical background. Implementing the required fields in the Page Layout seems to be the solution for this problem: both IW and visitors have the idea of the page will look after publishing.

But as I mentioned there seems to be a difference in information's interpretation for both the visitors and IW: how would you incorporate the required information ordered differently depending on the role of the user? The easiest solution would be to send the IW back to the blue edit screens of SharePoint 2007 and make that their working interface.

I've also found out that you will face the same challenge while dealing with a creative chrome which doesn't really allows or doesn't have space for in-place editing.

While dealing with this problem I came up with a solution: how about setting the ControlMode="Display" attribute for all the display (visitors) fields and incorporating the edit (IW) fields in the edit panel so they are visible only in the edit mode? A typical display field would look then like this:

<SharePointWebControls:TextField FieldName="SomeField" ControlMode="Display" runat="server" />

It worked fine until it came to working with required fields: the ControlMode attribute changes only the visual piece of a field: if it's required it will still need some input in order to be valid. After a little search I came up with another solution.

In one of the Page Layouts shipped with SharePoint 2007 I've found the SharePointWebControls:FieldValue webcontrol. After a little bit of testing it seems to suit the customer needs and solve my problem.

Each time you will want to make use of alternate fields order you can use the SharePointWebControls:FieldValue webcontrol instead of making a custom one.

Imtech Fields Explorer

August 24th, 2007 by waldek mastykarz

Imtech Fields Explorer is a tool that can help you during the development process while working with fields. The tool allows you to explore properties of the fields contained within the (Site Collection) Content Types and Lists.

To explore the existing fields simply input the URL of your Site (Collection) and press Enter (or click `Open'): you will then be able to choose whether you're interested in the Fields belonging to Content Types or Lists.

Imtech Fields Explorer

To improve the performance of the tool I have chosen to extend the TreeNode class. The extended node contains the IsLoaded property which determines whether the child nodes have been loaded. The child nodes are being loaded after selecting a node for the first time. Like this there is no overhead of loading items you don't need.

Imtech Fields Explorer: Available Content Types

For the convenience the available Content Types are grouped.

Imtech Fields Explorer: Field's Properties

After selecting a Field all of its properties will show in the property grid. I think the most useful are:

  • FieldValueType
  • Id
  • InternalName
  • SchemaXml
  • StaticName
  • Title
  • TypeAsString 

I have found out that I need those properties quite often during SharePoint 2007 solutions development.

Download Imtech Fields Explorer v1.1.0.0 (47,6KB) 

AddToEnvPath

August 24th, 2007 by waldek mastykarz

AddToEnvPath is a tiny tool which I wrote to help me add some path to the Environment Path variable. Like this you gain easy access to tools like STSADM.EXE and GACUTIL.EXE no matter the command line location.

It works pretty simple: addtoenvpath <your path> eg. Addtoenvpath C:MyFolder As I use the tool most of the times for setting the STSADM.EXE path, it's been hard coded in the tool. The tool will add it (C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12BIN) each time you run addtoenvpath without any parameters.

Download AddToEnvPath (2,16KB)

TechEd Developers 2007 Europe Vista gadget

August 23rd, 2007 by tmt

I searched the web for a countdown Vista gadget for the TechEd 2007 in Barcelona but could not find one. So I made one myself. I am not too sure if we could go there but now I can see in about how many days I am going… or not…

   

See attachment below to download the gadget in .zip format or download it here.

About John Bruin

August 21st, 2007 by tmt

Hello my name is John Bruin and I am 37 years old so I am the oldest and supposed to be the wisest of the three of us… I am working as Senior Software Engineer for Imtech ICT Business Solutions in The Netherlands. As a Microsoft .NET Certified Solution Developer I am building solutions in ASP.NET and SharePoint 2007. I have special interest in new technology and rich user experiences and therefore I like Silverlight, WPF and Vista Sidebar gadgets very much! My best achievement this year was winning the Rock My Website (sorry it is only in Dutch) contest together with Waldek and Martijn with a higly accessible and appealing website design for Stichting Drempelvrij.nl

My other personal interests are: International 10×10 draughts, PlayStation Portable and other gadgets, listening to music, watching movies and not to forget the good old Commodore 64 which I have grown up with.

I believe that it is very important to share my knowledge with colleagues and now in a bigger perspective with the whole SharePoint community. Learn and enjoy!