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.");
}
So we need to implement a workflow which provides us with a possibility to schedule item deletion and finally unpublish it from the front end upon confirmation.
The key point is additional workflow state named "Deletion Pending" which is referred by the "Schedule for Deletion" command.It has two commands: "Confirm Deletion" and "Reject Deletion". The first command unpublishes item and the second returns it to the "Published" state.
The "Process" method that is invoked by the "Unpublish" workflow action looks like this:
public void Process(WorkflowPipelineArgs args) { Error.AssertObject(args.DataItem, "args.DataItem"); Item item = args.DataItem;
Database web = Factory.GetDatabase("web"); Database master = Factory.GetDatabase("master");
using (new Sitecore.SecurityModel.SecurityDisabler()) { DeleteItem(web, item); DeleteItem(master, item);
// RemoveLinks(item); LinkManager.UpdateLink(item); }
Sitecore.Context.ClientPage.SendMessage(this, String.Format("item:refresh(id={0})", item.ID)); }
private void DeleteItem(Database db, Item item) { if (db.Items[item.ID] != null) { db.Items[item.ID].Delete(); Log.Info(String.Format("Item {0} was deleted from the {1} database using the workflow command.", item.Paths.FullPath, db), this); } else { Log.Info(String.Format("Deletion for the item {0} failed for the {1} database. Item not found.", item.Paths.FullPath, db), this); } }
I've found two cons so far:
Good luck.
<?xml version="1.0" encoding="utf-8" ?>
<control xmlns:def="Definition" xmlns="http://schemas.sitecore.net/Visual-Studio-Intellisense">
<PreviewCurrentWorkflowPortletdef:inherits="Custom.Portlets.PreviewCurrentWorkflowPortletXmlControl,CurrentWorkflowPortlet">
<Border def:ID="Portlet"><DefaultPortletWindow def:ID="Window" Header="Workflow Details" Icon="Network/16x16/inbox.png">
<Border def:ID="Body"/><Literal def:ID="Workflow" Text="Workflow: " />
<br /><Literal def:ID="WorkflowState" Text="Workflow State" />
</DefaultPortletWindow></Border>
</PreviewCurrentWorkflowPortlet></control>
6. Create a class that will stand for this XML control. Compile it and place into the bin folder. using System; using Sitecore; using Sitecore.Data.Items; using Sitecore.Web.UI.XmlControls; using Sitecore.Web.UI.HtmlControls; namespace Custom.Portlets { public class PreviewCurrentWorkflowPortletXmlControl : XmlControl { protected Border Body; protected Border Portlet; protected XmlControl Window; protected Literal WorkflowState; protected Literal Workflow; protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Sitecore.Context.ClientPage.IsEvent) { this.Window.ID = this.ID + "_window"; this.Portlet.Attributes["id"] = this.ID; Item item = UIUtil.GetItemFromQueryString(Sitecore.Context.ContentDatabase); string workflowID = item.Fields["__Workflow"].Value; string stateName = "none"; string workflowName = "none"; if(workflowID != "") { stateName = GetState(item, Sitecore.Context.Database, workflowID).DisplayName; workflowName = Sitecore.Context.Database.Items[new Sitecore.Data.ID(workflowID)].Name; } this.WorkflowState.Text += stateName; this.Workflow.Text += workflowName; } } private Sitecore.Workflows.WorkflowState GetState(Sitecore.Data.Items.Item item, Sitecore.Data.Database database, string workflowID) { // getting the workflow provider for the master database Sitecore.Workflows.IWorkflowProvider provider = database.WorkflowProvider; // getting the Simple workflow through the IWorkflow interface Sitecore.Workflows.IWorkflow iWorkflow = provider.GetWorkflow(workflowID); return iWorkflow.GetState(item); } } } 7. Add the reference to this dll into the web.config (UI » References section):" + Images.GetImage("Applications/48x48/exchange.png", 0x30, 0x30) + " Processed: " + status.Processed.ToString() + " |