Monday, December 26, 2005

Is a sublayout in use anywhere?


The following sample code may be useful if you want to know whether a sublayout is used anywhere.

   1: Sitecore.Context.SetActiveSite("shell");
   2: Database masterdb = Sitecore.Context.ContentDatabase;
   3:  
   4: // item for which we check sublayout reference
   5: Item item = masterdb.Items["/sitecore/content/home/test"];
   6:  
   7: // get Renderings field of the item
   8: string rend = item.Fields["__renderings"].Value;
   9: LayoutDefinition layout = LayoutDefinition.Parse(rend);
  10: DeviceItem dev = Sitecore.Context.Device;
  11: DeviceDefinition device = layout.GetDevice(dev.ID.ToString());
  12:  
  13: // the rendering which you want to check referrings to
  14: Item myrendering = masterdb.Items["/sitecore/layout/renderings/document"];
  15:  
  16: // get the rendering of our item
  17: RenderingDefinition rendering = device.GetRendering(myrendering.ID.ToString());
  18:  
  19: if(rendering != null){
  20:   Response.Write(String.Format("Item {0} links to the rendering {1}", item.Name, myrendering.Name));
  21: }
  22: else {
  23:   Response.Write(String.Format("Item {0} doesn't link to the rendering {1}", item.Name, myrendering.Name));
  24: }

Working with Session inside of XSLT


Here are two XSLT statements on how to set and retrieve the session value:
<!-- Setting the session -->
<xsl:value-of select="sc:SetSession('basket','1034=2|3200=1')"/>
<!-- Getting the session variable -->
<xsl:value-of select="sc:Session('basket')"/>
The following output can be observed on the front-end: 1034=2|3200=1

Startmenu in Sitecore v5


Sometimes when a user clicks the Sitecore button » All Applications, the list of all applictions may be displayed behind the menu. This beahvior is described at the picture below:
This can be cured by completing the following steps:
  1. Add the site to the list of the Trusted Sites as it is depicted below:
  2. Please make sure that the client machine has MSXML 4.0 and WinXP SP2 installed.
  3. Delete temporary internet files (IE/Options/Internet Options/Delete Files).

Friday, December 23, 2005

Thumbnails in Sitecore V4


You can use the web.config ImageTypes setting to set an additional image extension for which the thumbnail will be generated: <setting name="ImageTypes" value="|gif|jpg|png|tif|"/>

Thursday, December 22, 2005

Default Content Database


When you try running the code, the default context is set to the website. This means that all database definitions are taken from the website web.config section: ... name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" language="en" database="web" domain="extranet" allowDebug="true" cacheHtml="true" ... As can be seen, the content attribute is missing here, that’s why the content database is undefined. In other words, Sitecore.Context.ContentDatabase returns null. So the following actions can be taken in order to solve the problem: 1. Change the context to the site where the content database is defined. Here is statement to be used before calling Sitecore.Context.ContentDatabase property: Sitecore.Context.SetActiveSite("shell"); or Sitecore.Context.SetActiveSite("modules_shell"); 2. Add the content attribute like it is shown below: ... name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" language="en" database="web" domain="extranet" allowDebug="true" content="master" cacheHtml="true" ...

Thursday, December 08, 2005

Working with the Newsletter module for Sitecore V4


Here is the number of code snippets that might be useful: 1. Adding subscribers: Response.Write(" " + DateTime.Now.ToString()); MailingList list = new MailingList(); string mailinglistID = MasterFactory.GetItem("/sitecore/content/modules/mailing list/mailing lists/List1").ID; for (int i = 1; i <= 20000; i++) { string name = String.Concat("Name", i.ToString()); string company = ""; string country = Sitecore.State.Language; string email = String.Concat("Name", i.ToString(), "@company.com"); list.PutSubscriber(name, email, "", Sitecore.State.Language); list.Subscribe(name, email, mailinglistID); } Response.Write(" " + DateTime.Now.ToString()); 2. Edit subscriber’s mail: MailingList ml = new MailingList(); // getting the subscriber by e-mail XPathNavigator nav = ml.GetSubscriber("test@sitecore.net"); XmlNode node = MailingListHelper.ConvertToNode(nav); // retrieving subscriber's info string name = node.SelectSingleNode(@"/sitecore/subscriber/name").InnerText; string newEmail = "new@sitecore.net"; string company = node.SelectSingleNode(@"/sitecore/subscriber/company").InnerText; string country = node.SelectSingleNode(@"/sitecore/subscriber/country").InnerText; // adding a new subscriber with the new e-mail address ml.PutSubscriber(name, newEmail, company, country); // deleting the subscriber with old e-mail ml.DeleteSubscriber("test@sitecore.net"); 3. Reading mailing list: private void Page_Load(object sender, System.EventArgs e) { Sitecore.Modules.MailingList.MailingList mlist = new MailingList(); XPathNavigator xPathNavigator1 = mlist.GetSubscriber("at@sitecore.net"); if (xPathNavigator1 != null) { XPathNodeIterator xPathNodeIterator = xPathNavigator1.Select("/sitecore/subscriber"); if (xPathNodeIterator.MoveNext()) { XmlNode xmlNode1 = ((IHasXmlNode)xPathNodeIterator.Current).GetNode(); Response.Write(MailingListHelper.GetChildValue("name",xmlNode1)); Response.Write(" "); Response.Write(MailingListHelper.GetChildValue("email",xmlNode1)); Response.Write(" "); Response.Write(MailingListHelper.GetChildValue("company",xmlNode1)); Response.Write(" "); Response.Write(MailingListHelper.GetChildValue("country",xmlNode1)); Response.Write(" "); } } XmlNode node = MailingListHelper.ConvertToNode(mlist.GetMailingLists()); foreach(XmlNode list in node.SelectNodes("/sitecore/mailinglist")) { string nameList = XmlUtil.GetChildValue("name", list); string description = XmlUtil.GetChildValue("description", list); string ID = XmlUtil.GetAttribute("id", list); Response.Write("List name: " + nameList + " "); Response.Write("Description field: " + description + " "); Response.Write("List ID: " + ID + " "); IMasterItem itm = MasterFactory.GetItem(ID); if ( itm != null ) { string forTestOnly = itm.GetFieldValue("Test"); if ( forTestOnly.Equals("1") ) { Response.Write("For testing only is enabled" + " "); } else { Response.Write("For testing only is disabled" + " "); } } } XPathNavigator nav = mlist.GetMailingLists(); XPathNodeIterator node1 = nav.Select("/sitecore/mailinglist"); while (node1.MoveNext()) { string name = node1.Current.Evaluate("string(name)").ToString(); string id = node1.Current.GetAttribute("id", ""); XmlNode node2 = MailingListHelper.ConvertToNode( nav ); } 4. Read subscriber’s standard fields: Sitecore.Modules.MailingList.MailingList mlist = new MailingList(); XPathNavigator xPathNavigator1 = mlist.GetSubscriber("at@sitecore.net"); if (xPathNavigator1 != null) { XPathNodeIterator xPathNodeIterator = xPathNavigator1.Select("/sitecore/subscriber"); if (xPathNodeIterator.MoveNext()) { XmlNode xmlNode1 = ((IHasXmlNode)xPathNodeIterator.Current).GetNode(); Response.Write(MailingListHelper.GetChildValue("name",xmlNode1)); Response.Write(" "); Response.Write(MailingListHelper.GetChildValue("email",xmlNode1)); Response.Write(" "); Response.Write(MailingListHelper.GetChildValue("company",xmlNode1)); Response.Write(" "); Response.Write(MailingListHelper.GetChildValue("country",xmlNode1)); Response.Write(" "); } }

Disable HTML Tab in the HTML Editor


Applies to 5.1.1/5.2.

It is now controlled by security on /sitecore/system/Settings/Html Editor Profiles//Buttons/HTML view.

Please look at the picture below:

The result is depicted below:

Update: rumors say that in 5.3.1 it will work as it used to be in 5.1.1/5.2.

Starting URLs


In order to set up stating mode for a definite user, specify one of the following values in the "Start URL" field in the Properties window of the user: Desktop - /sitecore/shell/default.aspx Content Editor - /sitecore/shell/applications/clientusesoswindows.aspx Preview - /sitecore/shell/applications/preview.aspx

Reading sublayout's properties


Create a sublayout named “Document”, pass one parameter to it and performed publishing: The following code... Database db = Sitecore.Configuration.Factory.GetDatabase("master"); Item item = db.Items["/sitecore/content/home"]; string rend=item.Fields["__renderings"].Value; LayoutDefinition layout = LayoutDefinition.Parse(rend); DeviceItem dev = Sitecore.Context.Device; DeviceDefinition device = layout.GetDevice( dev.ID.ToString()); Item subl1 = db.Items["/sitecore/layout/Sublayouts/Document"]; RenderingDefinition rendering = device.GetRendering(subl1.ID.ToString()); Response.Write("Parameters: " + rendering.Parameters); ...should result the following output: Parameters: sab=sabvalue

Moving from Sitecore V4 to V5


The register directive should be changed to the following: <%@ register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %>. And all pages should be inherited from the System.Web.UI.Page class, rather than from the Sitecore.BasePage class.

Getting folder items from Media Library


Applied to Sitecore V5.1.x. In order to get a list containing all the folder items in the media library and use it as a source for the Multilist field, you can use the following approaches:
  • query:/sitecore/media library//*[@@templatename='Media folder'] - Returns all items and all subitems based on the Media folder template. Note that the templatename attribute is case sensitive.
  • query:/sitecore/media library/*[@@templatename='Media folder'] - Returns all items under the root of Media library based on the Media folder template.
  • query:/sitecore/media library//*[@@templatekey='media folder'] - Returns all items and all subitems based on the Media folder template. Here is another approach using the templatekey attribute.
  • query:/sitecore/media library/*[@@templatekey='media folder'] - Returns all items under the root of Media library based on the Media folder template.
You may find this link useful as well: http://sdn5.sitecore.net/SDN5/FAQ/API/Lookups%20with%20XPath.aspx

Thursday, December 01, 2005

Changing client default content language


Despite the simplicity of this solution, nevertheless I 've decided to publish it. It is possible to accomplish this by modifying your web.config file. You should add the contentLanguage attribute to the shell site in the section (it is shown in bold below):

contentLanguage="da"

Now your default content language should be changed to Danish.

Disabling workflows


There at least two ways to disable workflows: 1. Remove (or disable) workflowprovider in web.config for the master database: 2. Set enableWorkflow="true" for the site in web.config:

Setting access rights for a section


The key point to make a section visible is to make at least one section's field visible. Here are a few steps how to achieve this. 1. Go to the Template Manager and choose the Standard Template for editing. 2. Within the Template Editor choose any field in a section. 3. Locate the "Field Security" in the Data section, not the Security section and ensure that the Everyone role doesn't have denied read permission and enable any other role (e.g. Editors) to read it. 4. You can do the same for other fields inside the section. 5. Save changes. If you want to allow a user to edit the fields inside the section – just, using the described above technique, set Write permission for those fields to this user.

Deny access to the "Copy to" and "Delete subitems" menu items


You can tune up appropriate commands under /content/system/commands in the core database to fit your needs. Please look at the picture below: As a result, the following can be observed for the developer user:

HTML Editor profile tied up to definite field


The matter is that you can assign the whole profile to a certain HTML field. Go to the Template Editor, select a certain HTML field and fill the Source field with necessary profile. Please have a look at the image:

Rebuilding Search Indexes


We've got some cases regarding index problems. The possible errors that can be observed may look like the following ones:
  1. Could not find file "C:\sitecore\SitecoreInetpub\indexes\master\system\_1jql.fnm".

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.FileNotFoundException: Could not find file "C:\sitecore\SitecoreInetpub\indexes\master\system\_1jql.fnm".

  2. docs out of order

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.SystemException: docs out of order
This can be cured by completing the following. Rebuild your search indexes in the Control Panel (see the picture below): If it doesn't help, try to manually remove all index files in the following folders:
  • indexes/archive/archive
  • indexes/core/system
  • indexes/master/system
  • indexes/recycle bin/recycle bin
  • indexes/recyclebin/recyclebin

Retrieving created date from the Messageboard database


In order to read creation date of a definite message stored in the Messageboard database, the created element value from the XML should be used rather than the created_dt value. It has the following format: created 7/1/2003 1:18:28 PM It's much more convenient for the futher date formatting since the created_dt value does not contain any “pm” or “am” definitions. Then you can apply suggested code snippet in order to change the date format: string formatedData = dt.ToString("M/d/yyyy H:mm");