Sitecore 5.1 instructions:
|/sitecore modules/forum/web/|/users/avatar.aspx|/rss.aspx
Sitecore 5.2 instructions:
Helping developers build better solutions with Sitecore. Sharing ideas and best practices with the growing developer community.
Sitecore 5.1 instructions:
|/sitecore modules/forum/web/|/users/avatar.aspx|/rss.aspx
Sitecore 5.2 instructions:
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("."));
Response.Write(output);
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”.
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:
<frontendUpload>
<processor mode="on" type="Sitecore.Pipelines.Upload.Save, Sitecore.Kernel" />
</frontendUpload>
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
Sitecore.Context.SetActiveSite("shell");
// starting the pipeline previously added to web.config
PipelineFactory.GetPipeline("frontendUpload").Start(args);
// 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.Editing.BeginEdit();
itm.Fields["Alt"].Value = "Set from API";
itm.Editing.EndEdit();
}
// setting the active site back
Sitecore.Context.SetActiveSite("website");
}
}
else
{
Response.Write("No file is posted.");
}