Friday, December 29, 2006

Cannot create new groups in the Forum module

The solution is simple. Check if you modified the IgnoreUrlPrefixes setting according to the SDN5 instructions:

Sitecore 5.1 instructions:

|/sitecore modules/forum/web/|/users/avatar.aspx|/rss.aspx

Sitecore 5.2 instructions:

|/sitecore modules/forum/web/|/users/avatar.aspx|/rss.aspx|/WebResource.axd The thing is that the GroupRepeater control relies on the ItemCommand event which is not simply fired unless you add your page to the IgnoreUrlPrefixes list. This is applied to 5.1.1.x. Not sure that same problems exist in 5.3 though.

Tuesday, December 12, 2006

Using the XSL helper class from your code

Here is an easy way to output an image tag from an image field with possibility to use some new enhancements provided in 5.3.

Sitecore.Xml.Xsl.XslHelper xslhelper = new Sitecore.Xml.Xsl.XslHelper();

string output = xslhelper.image("ImageField", Factory.CreateItemNavigator(Sitecore.Context.Item).Select("."));


Understanding the Sort Order

1) In Sitecore 5.3 this code returns the home children in the same way as in Shell UI:

Item root = db.Items["/sitecore/content/home"];

ChildList list = root.GetChildren(ChildListOptions.IgnoreSecurity);

foreach (Item itm in list) { Response.Write(itm.Name); }

2) Sitecore sorts children according to their SortOrder field firstly.

3) If items do not have the SortOrder field filled or the values are equal Sitecore sorts it according to “Subitems Sorting” field value of the parent item.

4) You can apply your own sorting by writing your own IComparer. Please add your own
/sitecore/system/Settings/Subitems Sorting/* comparer with such code structure:

public class CreatedComparer : Comparer


protected override int DoCompare(Item item1, Item item2)


// return item1.Statistics.Created.CompareTo

// (item2.Statistics.Created);

return {0 or 1 or -1};



5) Note: you can apply this to all the items based on a certain template by setting it via “Standard Values”.

Uploading media items from the front end

Why not? What if you want the extranet users to upload media to the master database? No problem with that! Just follow these easy steps to accomplish this.

Step 1: add a new pipeline to the <processors> section in the web.config:


<processor mode="on" type="Sitecore.Pipelines.Upload.Save, Sitecore.Kernel" />


Step 2: Add the FileUpload control to your layout (web form):

<asp:FileUpload ID="FileUpload1" runat="server" />

This control will be used to select a image for uploading.

Step3: in the code behind of a layout you should add the following code for example in the button click handler.

// defining if a file is being uploaded

if (FileUpload1.PostedFile != null)


// disabling security in order to create a media item

using (new Sitecore.SecurityModel.SecurityDisabler())


// creating necessary arguments to be passed to the processor

UploadArgs args = new UploadArgs();

// adding http files collection

args.Files = base.Request.Files;

// a media path where the media item will be created

args.Folder = "/sitecore/media library/Files";

// we may want to override existing media items

args.Overwrite = true;

// we do not need to choose this option since we are uploading images, not archives

args.Unpack = false;

// turning on versioning for the uploaded item

args.Versioned = true;

// selecting a language in which the media item will be created

args.Language = Sitecore.Globalization.Language.Parse("en");

// we are uploading to the database

args.Destination = UploadDestination.Database;

// if we are uploading to the master database, we need to change the active site


// starting the pipeline previously added to web.config


// the media item is created. Now we can do whatever we want with the uploaded items

// for exampe, programmatically populate the Alt fields

foreach (Item itm in args.UploadedItems)



itm.Fields["Alt"].Value = "Set from API";



// setting the active site back






Response.Write("No file is posted.");