Tuesday, October 09, 2007
Windows Server 2008 RC0 and Visual Studio 2008 Beta2
Tuesday, July 17, 2007
Editing media files through the UI
This then the following approach can be used.
First of all, a special button should be added to the media tab. In order to do this, go to the core database -> and create a button under /sitecore/system/Ribbons/Contextual Ribbons/Media/Media/Media. The easiest way will be to duplicate the existing Download button and change the name to something more appropriate, e.g. "Edit File". Set the following properties:
- Header = Edit File
- Icon = Applications/16x16/contract.png
- Click = media:edit
- Tooltip = Edit the file.
The Click field is the most important. This value will connect the button with the execution logic.
Next step will be to define the "media:edit" command. Open the \app_config\Commands.config file and add something like:
<command name="media:edit" type="WebApp.Shell.Framework.Commands.Media.Edit,WebApp" />
This will tell Sitecore to look up the "WebApp.Shell.Framework.Commands.Media.Edit" class in the WebApp assembly from the bin folder.
So the only thing that is left to do is to compile the code that will execute an application to edit the file.
The code is represented below:
using Sitecore; using Sitecore.Data; using Sitecore.Data.Items; using Sitecore.Shell.Framework; using Sitecore.IO; using Sitecore.Text; using Sitecore.Shell.Framework.Commands;
namespace WebApp.Shell.Framework.Commands.Media { public class Edit : Command { public override void Execute(CommandContext context) { foreach (Item item in context.Items) { string filename = item["file path"]; if (FileUtil.FileExists(filename)) { UrlString url = new UrlString(); url.Append("fi", filename); if (filename.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) { Windows.RunApplication("Layouts/IDE", url.ToString()); return; } } } } } }
This is basically a class that inherits from the Command base class and contains one single method "Execute" that is fired whenever the button is clicked.
In the logic of this method we simply get the currently selected media item, get the physical path and check if this is an XML file. If it is, we execute the Developer Center application that allows us to edit and save the file. You can modify the logic to fit your needs.
This is how it looks like:
Note that this scenario deals with file system media storage. In case of database storage you will be able to download the media file from the blob field and reattach it to the same media item.
Monday, June 25, 2007
Briefly about HTTP Request Begin Pipeline
Though SCD2 Training mentions this quite interesting and sometimes useful topic, I decided to give a quick overview of what happens with the HTTP request when it comes to Sitecore.
- IgnoreList – checks if the requested page is in the ignore URL list in the web.config. The setting is called “IgnoreUrlPrefixes”. If such page is defined, the pipeline terminates.
- SiteResolver – resolving the site name either by the sc_site query string value or by host name or virtual folder name got as a result of parsing the incoming URL.
- DatabaseResolver – getting the Sitecore context database by the sc_database query string.
- DeviceResolver – getting the current Sitecore device by query string, User Agent or in any other supported way.
- LanguageResolver – getting Sitecore context language by the sc_lang query string.
- CustomHandlers – triggers custom handlers that are defined in the <customHandlers /> section.
- FilterUrlExtensions – define the allowed/blocked extensions that will be either streamed or not.
- QueryStringResolver – analyzing such query string as “sc_itemid”. If the ID specified as the value is valid and if the item is found in the context database, then the returning item is set as a context item.
- AliasResolver – if the requested URL matches an alias that exist in the system, Sitecore processes either external URL or the real item that is associated with this alias.
- DefaultResolver – getting the start path item for the context site. Sitecore instantiates this item using the “RootPath” and “StartItem” attributes of the context site by simply concatenating these values.
- ItemResolver – getting the Sitecore context item by the incoming URL.
- LayoutResolver – returning the presentation logic for the resolved item.
- ExecuteRequest – context path rewrite and handling of the “item not found”/”layout not found” errors.
Wednesday, June 13, 2007
Insert Sitecore Link dialog - another icon
You can change it by changing the Icon field of the "Insert Sitecore Link" item: /sitecore/system/Settings/Html Editor Profiles/<name of the profile that you use>/Toolbar 1/Insert Sitecore Link
Here is the image you can use as a source.
Copy this image to \sitecore\shell\RadControls\Editor\Skins\Monochrome\Buttons\
Here is the result:
Look much better now and less confusing for the editors. Please don’t forget to copy the file when upgrading in future.
Friday, May 18, 2007
Adding User Activation Step
You may have a requirement to have user activation in your solution.
The easiest way to do this is to extend the User template in the Security Tempalates.xml file by adding an additional field that will serve as an activation flag defining if the user can be logged in. After that you will add additional step to the login process pipeline and abort it if the user is not activated.
So here are the steps:
1. Add an additional field named “Active” for the User template as you have already did for the profiles:
<field id="{E20FD18B-6F85-4A71-A086-BEE3C0546211}" name="Active" icon="" shared="1" sortorder="" source="" style="" type="checkbox" unversioned="1"/>
After that you should be able to see the Active checkbox in the User Properties window.
2. Compile the following code and place to the bin folder:
using Sitecore.Pipelines.Login;
namespace WiseBusiness.Pipelines.Login { public class IsActive { public void Process(LoginArgs args) { // we do not want to check security for the anonymous user // also we exclude admins from this process if (Sitecore.Context.IsLoggedIn && !(Sitecore.Context.IsAdministrator) && !(Sitecore.Context.User.InnerItem["Active"] == "1")) { args.Success = false; args.Warning = String.Format("Your login was not successful, the user {0} is not activated.", args.Username); args.Abort(); } } } }
3. Add this processor definition to the web.config below the Sitecore.Pipelines.Login.Login processor:
<login argsType="Sitecore.Pipelines.Login.LoginArgs">
... <processor mode="on" type="Sitecore.Pipelines.Login.Login, Sitecore.Kernel" /> <processor mode="on" type="WiseBusiness.Pipelines.Login.IsActive, webapp" /> ...
</login>
Notes:
1. Developed for 5.3.1 (rev. 070417)
2. Was not thoroughly tested, so provided "as is".


