<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emesa Solutions</title>
	<atom:link href="http://emesasolutions.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://emesasolutions.com</link>
	<description>Consulting in Microsoft and Sitecore Technologies</description>
	<lastBuildDate>Tue, 20 Mar 2012 20:33:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to write your own language resolver and link manager in Sitecore</title>
		<link>http://emesasolutions.com/how-to-write-your-own-language-resolver-and-link-manager-in-sitecore/</link>
		<comments>http://emesasolutions.com/how-to-write-your-own-language-resolver-and-link-manager-in-sitecore/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 20:03:02 +0000</pubDate>
		<dc:creator>Tarek</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://emesasolutions.com/?p=277</guid>
		<description><![CDATA[Sometimes you may have to customize the site URLs depending on the language and Sitecore offers a way to do that in the LinkManager item in the web.config file but it&#8217;s very basic and so this is one case where &#8230; <a href="http://emesasolutions.com/how-to-write-your-own-language-resolver-and-link-manager-in-sitecore/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you may have to customize the site URLs depending on the language and Sitecore offers a way to do that in the LinkManager item in the web.config file but it&#8217;s very basic and so this is one case where you would want to create your own Language Resolver and Link Manager classes.</p>
<p><span id="more-277"></span>Let&#8217;s take a look at the default link manager item in the web.config file</p>
<pre class="brush: xml; gutter: true">    &lt;!-- LINKS --&gt;
    &lt;!-- Options (first is default):
           addAspxExtension: true | false (If you set this to false, remember to configure IIS to map all requests (*) to ASP.NET)
           alwaysIncludeServerUrl: false | true
           encodeNames: true | false
           languageEmbedding: asNeeded | always | never
           languageLocation: filePath | queryString
           shortenUrls: true | false
           useDisplayName: false | true
    --&gt;
    &lt;linkManager defaultProvider=&quot;sitecore&quot;&gt;
      &lt;providers&gt;
        &lt;clear/&gt;
        &lt;add name=&quot;sitecore&quot;
             type=&quot;Sitecore.Links.LinkProvider, Sitecore.Kernel&quot;
             addAspxExtension=&quot;true&quot;
             alwaysIncludeServerUrl=&quot;false&quot;
             encodeNames=&quot;true&quot;
             languageEmbedding=&quot;asNeeded&quot;
             languageLocation=&quot;filePath&quot;
             shortenUrls=&quot;true&quot;
             useDisplayName=&quot;false&quot;/&gt;
      &lt;/providers&gt;
    &lt;/linkManager&gt;</pre>
<p>Let&#8217;s say we have a bilingual site, English (en) and French Canadian (fr-CA), and we want the URLs to look like this:</p>
<p>en: http://website.com/AboutUs.aspx<br />
fr-CA: http://website.com/<strong>fr</strong>/AboutUs.aspx</p>
<p>We can&#8217;t accomplish that with the default link manager, because if the languageEmbedding = always, the URL&#8217;s would look like this:</p>
<p>en: http://website.com/<strong>en</strong>/AboutUs.aspx<br />
fr-CA: http://website.com/<strong>fr-CA</strong>/AboutUs.aspx</p>
<p>The solution is to write our own language resolver class that would resolve the &#8220;fr&#8221; to &#8220;fr-CA&#8221; and not providing a language would set the language to English.</p>
<p><strong>Language Resolver</strong></p>
<p>We need two things:</p>
<ul>
<li>Set the languageEmbedding property in the LinkManager to &#8220;always&#8221;</li>
<li>Create our language resolver class</li>
<li>Patch the web.config file</li>
</ul>
<p><strong>Set the languageEmbedding property in the LinkManager to &#8220;always&#8221;</strong></p>
<p>For now, change the property to &#8220;always&#8221; in the web.config.  We will create our own later on and patch the config but for now we need it to test our language resolver class.</p>
<p><strong>Create our language resolver class</strong></p>
<p>Create a new class in your project and inherit it from &#8220;HttpRequestProcessor&#8221;, here&#8217;s the code:</p>
<pre class="brush: csharp; gutter: true">using Sitecore.Data.Managers;
using Sitecore.Pipelines.HttpRequest;
using Sitecore.Web;

namespace Sitecore.Starterkit.Helpers
{
    public class DemoLanguageResolver : HttpRequestProcessor
    {
        public override void Process(HttpRequestArgs args)
        {
            // args.Context.Request.RawUrl = &quot;/fr-CA/Services.aspx?sc_lang=en&quot;

            var languageName = WebUtil.ExtractLanguageName(args.Context.Request.RawUrl);

            var languageParameter = WebUtil.ExtractUrlParm(&quot;sc_lang&quot;, args.Context.Request.RawUrl);

            var language = string.IsNullOrEmpty(languageParameter) ? languageName : languageParameter;

            Context.Language = LanguageManager.GetLanguage(language.StartsWith(&quot;fr&quot;) ? &quot;fr-CA&quot; : &quot;en&quot;);
        }
    }
}</pre>
<p>I used the &#8220;WebUtil&#8221; class to extract the language name and &#8220;sc_lang&#8221; parameter, which changes the language in Sitecore.</p>
<p>All what I&#8217;m doing is checking to see if the language is passed in the parameter or embedded in the URL, extract it then check if it starts with &#8220;fr&#8221;, if so use &#8220;fr-CA&#8221; otherwise use &#8220;en&#8221;.</p>
<p><strong>Patch the web.config file</strong></p>
<p>The default language resolver is defined in the web.config file in under &#8220;pipelines &gt; httpRequestBegin&#8221;</p>
<pre class="brush: xml; gutter: true">&lt;processor type=&quot;Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel&quot;/&gt;</pre>
<p>Create a new config file and call it &#8220;LanguageResolver.config&#8221; (this could be named anything) in [\Website\App_Config\Include] and add the following:</p>
<pre class="brush: xml; gutter: true">&lt;configuration xmlns:patch=&quot;http://www.sitecore.net/xmlconfig/&quot;&gt;
  &lt;sitecore&gt;
    &lt;pipelines&gt;
      &lt;httpRequestBegin&gt;
        &lt;processor type=&quot;Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel&quot;&gt;
          &lt;patch:delete /&gt;
        &lt;/processor&gt;
        &lt;processor type=&quot;Sitecore.Starterkit.Helpers.DemoLanguageResolver, Sitecore.Starterkit&quot;
                   patch:after=&quot;processor[@type=&#039;Sitecore.Pipelines.HttpRequest.DeviceResolver, Sitecore.Kernel&#039;]&quot; /&gt;
      &lt;/httpRequestBegin&gt;
    &lt;/pipelines&gt;
  &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
<p>We delete the existing processor then add ours to the list right after the DeviceResolver.</p>
<p>Rebuild the project. If we browse the site and go to (some page in your site) &#8220;http://website.com/AboutUs.aspx&#8221; we get the English version and &#8220;http://website.com/<strong>fr</strong>/AboutUs.aspx&#8221;  we get the French Canadian version.</p>
<p>The only problem left is the links generated for the items on the site will still use the old URLs with &#8220;en&#8221; and &#8220;fr-CA&#8221; embedded.</p>
<p><strong>Link Manager</strong></p>
<ul>
<li>Create our link manager class</li>
<li>Patch the web.config file</li>
</ul>
<p><strong> Create our link manager class</strong></p>
<p>Create a new class in your project and inherit it from &#8220;LinkProvider&#8221;, here&#8217;s the code:</p>
<pre class="brush: csharp; gutter: true">using Sitecore.Data.Items;
using Sitecore.Links;

namespace Sitecore.Starterkit.Helpers
{
    public class DemoLinkManager : LinkProvider
    {
        public override string GetItemUrl(Item item, UrlOptions options)
        {
            var url = base.GetItemUrl(item, options);

            url = url.Contains(&quot;/en/&quot;) ?
                    url.Replace(&quot;/en/&quot;, &quot;/&quot;) :
                    url.Replace(&quot;/en.aspx&quot;, &quot;/en&quot;);

            url = url.Contains(&quot;/fr-CA/&quot;) ?
                    url.Replace(&quot;/fr-CA/&quot;, &quot;/fr/&quot;) :
                    url.Replace(&quot;/fr-CA.aspx&quot;, &quot;/fr&quot;);

            return url;
        }
    }
}</pre>
<p>All I did was replace the &#8220;fr-CA&#8221; with &#8220;fr&#8221; and remove &#8220;en&#8221; from the URL. The home page is special because the page name is the language name and it has the &#8220;aspx&#8221; extension.</p>
<p><strong>Patch the web.config file</strong></p>
<p>Create a new config file and call it &#8220;LinkManager.config&#8221; in [\Website\App_Config\Include] and add the following:</p>
<pre class="brush: xml; gutter: true">&lt;configuration xmlns:patch=&quot;http://www.sitecore.net/xmlconfig/&quot;&gt;
  &lt;sitecore&gt;
    &lt;linkManager&gt;
      &lt;patch:attribute name=&quot;defaultProvider&quot;&gt;MyLinkManager&lt;/patch:attribute&gt;
      &lt;providers&gt;
        &lt;add name=&quot;MyLinkManager&quot;
             type=&quot;Sitecore.Starterkit.Helpers.DemoLinkManager, Sitecore.Starterkit&quot;
             addAspxExtension=&quot;true&quot;
             alwaysIncludeServerUrl=&quot;false&quot;
             encodeNames=&quot;true&quot;
             languageEmbedding=&quot;always&quot;
             languageLocation=&quot;filePath&quot;
             shortenUrls=&quot;true&quot;
             useDisplayName=&quot;false&quot;/&gt;
      &lt;/providers&gt;
    &lt;/linkManager&gt;
  &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
<p>We set the default link manager to our custom class and add it as a provider.  The only thing I changed is the languageEmbedding property, changed it to &#8220;always&#8221;.</p>
<p>If you browse the site you should see that all the links now show &#8220;fr&#8221; instead of &#8220;fr-CA&#8221; for the French links and no &#8220;en&#8221; in the English links.</p>
<p><strong>In Summary</strong></p>
<p>By creating custom language resolver and link manager classes we are able to customize the URLs as we like without affecting the data.  Note, if you want to confirm that your web.config file patches are working, browse your site/sitecore/admin/showconfig.aspx  login as the admin if you&#8217;re not already and search for &#8220;LinkManager&#8221; and &#8220;LanguageResolver&#8221;.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://emesasolutions.com/how-to-write-your-own-language-resolver-and-link-manager-in-sitecore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to manage user defined template fields in code</title>
		<link>http://emesasolutions.com/how-to-manage-user-defined-template-fields-in-code/</link>
		<comments>http://emesasolutions.com/how-to-manage-user-defined-template-fields-in-code/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 22:12:59 +0000</pubDate>
		<dc:creator>Tarek</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://emesasolutions.com/?p=226</guid>
		<description><![CDATA[If you want to reference one of the built-in fields in Sitecore you would use something like: Sitecore.Context.Item.Fields[Sitecore.FieldIDs.DisplayName] However, if you want to use your own custom fields you would use: Sitecore.Context.Item.Fields["Title"]; A better way would be to use a class that &#8230; <a href="http://emesasolutions.com/how-to-manage-user-defined-template-fields-in-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to reference one of the built-in fields in Sitecore you would use something like: Sitecore.Context.Item.Fields[Sitecore.FieldIDs.DisplayName]<br />
However, if you want to use your own custom fields you would use: Sitecore.Context.Item.Fields["Title"];</p>
<p>A better way would be to use a class that references the field names instead of using strings everywhere in your application.  In order to do that we&#8217;re going to use Microsoft CodeDOM (<a href="http://msdn.microsoft.com/en-us/library/650ax5cx.aspx">http://msdn.microsoft.com/en-us/library/650ax5cx.aspx</a>).</p>
<p>We are going to do the following:</p>
<ul>
<li>Create custom templates with fields</li>
<li>Create an aspx page to generate the class</li>
<li>Add the CodeDom code to generate the class and fields</li>
</ul>
<p><span id="more-226"></span></p>
<p><strong>Create custom templates</strong></p>
<p>I created two templates in <em>/sitecore/templates/User Defined</em>, Breadcrumb [Title] and Site Section [Title, Description, Banner Image]</p>
<p><strong>Create an aspx page to generate the class</strong></p>
<p>We&#8217;ll create a page in [site directory]\Website\sitecore\admin\ and call it FieldsGenerator.aspx</p>
<p>This page will contain the code to generate the class with the our custom fields as properties and the location of the class will be in a folder in my project called &#8220;Helpers&#8221;, could be anywhere else.</p>
<p>Mine is here: C:\inetpub\wwwroot\Website1\Website\Helpers\Website1Fields.cs</p>
<p><strong>Code-behind using CodeDom</strong></p>
<p>The following code connects to the master database and grabs a unique list of all the fields in all the templates under <em>/sitecore/templates/User Defined</em></p>
<p>Then uses CodeDom to create the namespace, class and fields then writes the generated class to C:\inetpub\wwwroot\Website1\Website\Helpers\Website1Fields.cs</p>
<p>In the process we print out the fields&#8217; names on the screen.</p>
<pre class="brush: csharp; gutter: true">using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using System.Reflection;

namespace Website1.sitecore.admin
{
    public partial class FieldsGenerator : System.Web.UI.Page
    {
        // generated file name and path
        private const string FilePath = @&quot;C:\inetpub\wwwroot\Website1\Website\Helpers\Website1Fields.cs&quot;;

        protected void Page_Load(object sender, EventArgs e)
        {
            // admin and logged in
            if (Sitecore.Context.IsLoggedIn &amp;&amp; Sitecore.Context.User.IsAdministrator)
            {
                GenerateClass();
            }
            else
            {
                // redirect user to the login page
                Response.Redirect(string.Format(&quot;~/sitecore/admin/login.aspx?returnUrl={0}&quot;,
                    this.Request.RawUrl), true);
            }
        }

        private void GenerateClass()
        {
            var master = Sitecore.Configuration.Factory.GetDatabase(&quot;master&quot;);

            // create a list of unique field names from all templates under &quot;/sitecore/templates/User Defined&quot;
            var fieldNames = (master.SelectItems(&quot;/sitecore/templates/User Defined//*[@@templatename=&#039;Template field&#039;]&quot;)
                .OrderBy(item =&gt; item.Name).Select(item =&gt; item.Name)).Distinct();

            var codeCompileUnit = new CodeCompileUnit();

            // create the namespace
            var codeNamespace = new CodeNamespace(&quot;Website1.Helpers&quot;);
            codeCompileUnit.Namespaces.Add(codeNamespace);

            // create the class and add comments
            var codeClass = new CodeTypeDeclaration(&quot;Website1Fields&quot;) { IsClass = true, TypeAttributes = TypeAttributes.Public };
            codeClass.Comments.Add(new CodeCommentStatement(string.Format(&quot;\n\tClass generated date and time: {0}&quot;, DateTime.Now.ToString(&quot;dddd, MMMM dd, yyyy h:mm:ss tt&quot;))));
            codeClass.Comments.Add(new CodeCommentStatement(&quot;\n\tFields generated from templates in /sitecore/templates/User Defined&quot;));
            codeClass.Comments.Add(new CodeCommentStatement(&quot;\n\tSitecore query used: /sitecore/templates/User Defined//*[@@templatename=&#039;Template field&#039;]\n&quot;));
            codeNamespace.Types.Add(codeClass);

            // iterate through the fields and add them to the class as properties
            foreach (var fieldName in fieldNames)
            {
                var codeMemberField = new CodeMemberField()
                                      {
                                          Name = fieldName.Replace(&quot; &quot;, &quot;&quot;).Replace(&quot;-&quot;, &quot;&quot;),
                                          Type = new CodeTypeReference(typeof(string)),
                                          Attributes = MemberAttributes.Public | MemberAttributes.Const,
                                          InitExpression = new CodePrimitiveExpression(fieldName)
                                      };

                codeClass.Members.Add(codeMemberField);

                Response.Write(fieldName + &quot;&lt;br&gt;&quot;);
            }

            // create/update the class file
            using (var sw = new StreamWriter(FilePath))
            {
                var provider = CodeDomProvider.CreateProvider(&quot;CSharp&quot;);
                provider.GenerateCodeFromCompileUnit(codeCompileUnit, sw, new CodeGeneratorOptions { BracingStyle = &quot;C&quot; });

                Response.Write(&quot;&lt;h1&gt;Class generated!&lt;h1/&gt;&quot;);
            }
        }
    }
}</pre>
<p>Now if we browse the page, in my case http://website1/sitecore/admin/FiedsGenerator.aspx then open the generated class we should get the following:</p>
<pre class="brush: csharp; gutter: true">//------------------------------------------------------------------------------
// &lt;auto-generated&gt;
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.225
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// &lt;/auto-generated&gt;
//------------------------------------------------------------------------------

namespace Website1.Helpers
{

    //
    //	Class generated date and time: Sunday, March 04, 2012 5:01:32 PM
    //
    //	Fields generated from templates in /sitecore/templates/User Defined
    //
    //	Sitecore query used: /sitecore/templates/User Defined//*[@@templatename=&#039;Template field&#039;]
    //
    public class Website1Fields
    {

        public const string BannerImage = &quot;Banner Image&quot;;

        public const string Description = &quot;Description&quot;;

        public const string Title = &quot;Title&quot;;
    }
}</pre>
<p>Done. Now anywhere in my application I can reference a field like this:</p>
<p>Sitecore.Context.Item.Fields[Website1.Helpers.Website1Fields.Title]</p>
<p><strong>In Summary</strong></p>
<p>The class generation code could be in another project but for this simple site I placed it in the admin directory.  You only have to regenerate the class (browse the page) when you change an existing field or add a new field.  And with this approach you can take advantage of existing rename functions in Visual Studio instead of dealing Find &amp; Replace with strings.</p>
]]></content:encoded>
			<wfw:commentRss>http://emesasolutions.com/how-to-manage-user-defined-template-fields-in-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create applications in Sitecore using asp.net pages</title>
		<link>http://emesasolutions.com/how-to-create-applications-in-sitecore-using-asp-net-pages/</link>
		<comments>http://emesasolutions.com/how-to-create-applications-in-sitecore-using-asp-net-pages/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 17:40:41 +0000</pubDate>
		<dc:creator>Tarek</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://tareknasser.com/?p=109</guid>
		<description><![CDATA[You can create applications either by using Sitecore&#8217;s Sheer UI (xaml like syntax) or an asp.net web page.  In this post we&#8217;ll create an application using a web page to display information about the home item&#8217;s descendants. We need to &#8230; <a href="http://emesasolutions.com/how-to-create-applications-in-sitecore-using-asp-net-pages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You can create applications either by using Sitecore&#8217;s Sheer UI (xaml like syntax) or an asp.net web page.  In this post we&#8217;ll create an application using a web page to display information about the home item&#8217;s descendants.</p>
<p>We need to do two things:</p>
<ul>
<li>Create the application, UI + logic</li>
<li>Create the application and shortcut in Sitecore</li>
</ul>
<p><span id="more-109"></span></p>
<p><strong>Create the application, UI + logic</strong></p>
<p>First we need to decide where to create the web page, for this example I&#8217;m going to create it in: [Website1\Website\sitecore\admin\DisplayInfo.aspx]</p>
<p>In the front-end I added a grid view to display the items and styled the background to white:</p>
<pre class="brush: html; gutter: true">&lt;!-- header, etc. --&gt;
&lt;body style=&quot;background-color: #fff&quot;&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
    &lt;div&gt;
        &lt;asp:GridView runat=&quot;server&quot; ID=&quot;gvInfo&quot; AutoGenerateColumns=&quot;true&quot; /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Code-behind, even though this page will be accessed from Sitecore desktop we still need to check for security permissions and in case the page is accessed outside of the desktop.  Simply, load the home item&#8217;s descendants in the grid view.</p>
<pre class="brush: csharp; gutter: true">using System;

namespace Website1.sitecore.admin
{
    public partial class DisplayInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // check if user is logged in and is either the administrator or belongs to the MyRole role
            if (Sitecore.Context.IsLoggedIn &amp;&amp; (Sitecore.Context.User.IsInRole(@&quot;sitecore\MyRole&quot;) ||
                                                Sitecore.Context.User.IsAdministrator))
            {
                var masterDb = Sitecore.Data.Database.GetDatabase(&quot;master&quot;);

                gvInfo.DataSource = masterDb.SelectItems(&quot;/sitecore/content/Home//*&quot;);
                gvInfo.DataBind();
            }
            else
            {
                // redirect user to the login page
                Response.Redirect(string.Format(&quot;~/sitecore/admin/login.aspx?returnUrl={0}&quot;,
                    this.Request.RawUrl), true);
            }
        }
    }
}</pre>
<p>So far we created our simple app to display info about the home item&#8217;s descendants. Browse: http://website1/sitecore/admin/displayinfo.aspx  (replace website1 with your Sitecore instance)</p>
<p>If you&#8217;re not logged in you&#8217;ll be redirected to the admin login page; otherwise, you will see the list of items under your site&#8217;s Home item, mine looks like this:</p>
<p><a href="http://tareknasser.com/wp-content/uploads/2012/02/displayinfo-page.png"><img class="alignnone  wp-image-179" title="displayinfo-page" src="http://tareknasser.com/wp-content/uploads/2012/02/displayinfo-page.png" alt="" width="645" height="160" /></a></p>
<p><strong>Create the shortcut and reference the page in Sitecore</strong></p>
<p>Switch to Sitecore and login to the desktop then select the core database. <a href="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-select-db.png"><img class="alignright size-full wp-image-59" title="sitecore-select-db" src="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-select-db.png" alt="" width="145" height="119" /></a></p>
<p>Open the content editor and navigate to [/sitecore/content/Applications]</p>
<p>Insert an application from the insert menu and call it: Display Info</p>
<p>Enter the page location in the [Application] field: /sitecore/admin/displayinfo.aspx</p>
<p>Have a look at the other fields like icon, chrome and window state and size.</p>
<p>Now that we created the application item we&#8217;re going to add it to [Start Menu &gt; All Applications] by navigating to [/sitecore/content/Documents and settings/All users/Start menu/Programs]</p>
<p>Insert a new application shortcut from the insert menu and call it: Display Info</p>
<p>In the [Application] field enter: /Applications/Display Info</p>
<p>Save your changes and refresh the desktop and you should see the application in the start menu under [Start Menu &gt; All Applications &gt; Display Info]</p>
<p><strong>In Summary</strong></p>
<ul>
<li>Create the asp.net page</li>
<li>Check for permissions</li>
<li>Test the page outside of Sitecore desktop by browsing it; just makes it easier</li>
<li>Add a new application in content editor in the core database</li>
<li>Add a shortcut to the application in the start menu</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://emesasolutions.com/how-to-create-applications-in-sitecore-using-asp-net-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add commands to the ribbon in content editor</title>
		<link>http://emesasolutions.com/how-to-add-commands-to-the-ribbon-in-content-editor/</link>
		<comments>http://emesasolutions.com/how-to-add-commands-to-the-ribbon-in-content-editor/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 23:14:04 +0000</pubDate>
		<dc:creator>Tarek</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://tareknasser.com/?p=36</guid>
		<description><![CDATA[We need to do three things: Create the code to execute when the ribbon button is clicked Configure Sitecore to connect the button to the code Create the button in the ribbon Create the code to execute when the ribbon &#8230; <a href="http://emesasolutions.com/how-to-add-commands-to-the-ribbon-in-content-editor/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We need to do three things:</p>
<ul>
<li>Create the code to execute when the ribbon button is clicked</li>
<li>Configure Sitecore to connect the button to the code</li>
<li>Create the button in the ribbon</li>
</ul>
<p><span id="more-36"></span></p>
<p><strong>Create the code to execute when the ribbon button is clicked</strong></p>
<p>Let&#8217;s start with setting up the code, we need to create the command class and method to execute the command. I prefer to create a separate project for commands and other custom functions but for the sake of this example let&#8217;s create a folder under the [Website] directory and call it [Helpers] then create the class there and call it [DisplayInfo].</p>
<p>[\Website\Helpers\DisplayInfo.cs]</p>
<p>The following code displays a message box with the item name:</p>
<pre class="brush:csharp">using System;
using Sitecore.Shell.Framework.Commands;

namespace Website1.Helpers
{
    [Serializable]
    public class DisplayInfo : Command
    {
        public override void Execute(CommandContext context)
        {
            // get the selected item
            var item = context.Items[0];

            // display message box with the item&#039;s name
            Sitecore.Context.ClientPage.ClientResponse.Alert(&quot;Item Name: &quot; + item.Name);
        }
    }
}</pre>
<p>Build the project.</p>
<p><strong>Configure Sitecore to connect the button to the code</strong></p>
<p>To configure Sitecore we have to modify the [web.config] file. We&#8217;ll do that by creating a new config file in [\Website\App_Config\Include\Commads.config] you can call it anything you want, I&#8217;ll use Commands.config.</p>
<p>The following XML adds the command to the main [web.config] file.  The [name] is the text we will use later when we create the button, it is the key that will link the button the code, I used the format [site name : command name], my website is called [Website1] so [Website1:DisplayInfo]</p>
<p>The [type] lists the namespace, class and the dll where the class is located. From the code above, the namespace and class is [Website1.Helpers.DisplayInfo] and the dll is the project&#8217;s dll, Website1.dll</p>
<pre class="brush: xml; gutter: true">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
  &lt;sitecore database=&quot;SqlServer&quot;&gt;
    &lt;commands&gt;
      &lt;command name=&quot;Website1:DisplayInfo&quot;
               type=&quot;Website1.Helpers.DisplayInfo, Website1&quot;/&gt;
    &lt;/commands&gt;
  &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
<p><strong>Create the button in the ribbon </strong></p>
<p>Now let&#8217;s create the button in the ribbon, we&#8217;ll place it in the [Home] strip in its own chunk (group).</p>
<p>Let&#8217;s begin by logging into the desktop and switching to the [Core] database:</p>
<p><a href="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-select-db.png"><img class="size-full wp-image-59 alignnone" title="sitecore-select-db" src="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-select-db.png" alt="" width="145" height="119" /></a></p>
<p>Open the content editor and navigate to [/sitecore/content/Applications/Content Editor/Ribbons/Chunks]</p>
<p><a href="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-insert-from-template.png"><img class="alignright size-medium wp-image-61" title="sitecore-insert-from-template" src="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-insert-from-template-249x300.png" alt="" width="249" height="300" /></a></p>
<p>Here we will add a new chunk and call it [Item Info]:</p>
<ul>
<li>Right click on [Chunks] and select insert from template</li>
<li>In the dialog, navigate to and select [/System/Ribbon/Chunk]</li>
<li>Call it: Item Info</li>
<li>Create the item</li>
</ul>
<p>Insert &#8220;Item Info&#8221; in the  [Header] field and save.</p>
<p>Now we&#8217;ll create a [Large Button] in the chunk, right click then select insert from template and navigate to [/System/Ribbon/Large Button] and call it: Display Info</p>
<p>Insert &#8220;Display Info&#8221; in the [Header] field and save.</p>
<p>Pick an icon, I chose [Applications/32x32/about.png]</p>
<p>In the [Click] field insert the [name] we used in the [Commads.config] file which was [Website1:DisplayInfo] and save the changes.</p>
<p><a href="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-button-info.png"><img class="alignnone size-medium wp-image-77" title="sitecore-button-info" src="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-button-info-300x242.png" alt="" width="300" height="242" /></a></p>
<p>So far we have created the button and the chunk (group) that contains the button, the last step is to add it to the [Home] strip.</p>
<p>Navigate to<br />
[/sitecore/content/Applications/Content Editor/Ribbons/Strips/Home]</p>
<p>Right click and select insert from template then navigate to and select [/System/Reference] and call it: Item Info</p>
<p>In the [Reference] field select [/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Item Info] and save.</p>
<p>Close the content editor and open it again and you should see the button in the ribbon in the [Home] strip.</p>
<p><strong>Done</strong></p>
<p><a href="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-button-message.png"><img class="alignnone size-medium wp-image-81" title="sitecore-button-message" src="http://tareknasser.com/wp-content/uploads/2012/02/sitecore-button-message-300x203.png" alt="" width="300" height="203" /></a></p>
<p><strong>In summary</strong></p>
<ul>
<li>Add the class and the code to execute to your project</li>
<li>Add the Commands.config file and populate the name and type according to your class, namespace and dll</li>
<li>Login to Sitecore desktop and switch to the core database</li>
<li>Add the chuck</li>
<li>Add the button to the chunk</li>
<li>Add a reference to the chunk in the strip</li>
<li>Build and reload the site</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://emesasolutions.com/how-to-add-commands-to-the-ribbon-in-content-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

