Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, June 5, 2013

Get URL of Sitecore item

var directionItem = Sitecore.Context.Database.SelectSingleItem(Sitecore.Context.Site.StartPath + "//*[@@templatename='Hotel Directions']");

string directionURL = directionItem != null ? LinkManager.GetItemUrl(directionItem) : "";

Glass Library Implementation in Sitecore Project

1.    Install Package Managar in Visual Studio
a.    Go to Tools->Extension Manager-> click Online Gallery -> NuGet Package Manager. Download & install it
2.    Install Glass library
a.    Go to Tools-> Library Package Manager->Package Manager Console
Type command PM>"Install-Package Glass.Sitecore.Mapper" & press enter
3.    Create folder "Model" in your visual Studio project.
4.    Add cs file like "SitecoreHome.cs" in Model folder which map to content/template fields of sitecore


5.    Add following code in “Global.asax

public void Application_Start() {

var loader = new Glass.Sitecore.Mapper.Configuration.Attributes.AttributeConfigurationLoader(
            "WebApplicationRND.Model, WebApplicationRND");

Glass.Sitecore.Mapper.Context context = new Glass.Sitecore.Mapper.Context(loader);

  }

6.    Try to access it from web page code behind file as

Glass.Sitecore.Mapper.ISitecoreContext context = new Glass.Sitecore.Mapper.SitecoreContext();
var home = context.GetCurrentItem<WebApplicationRND.Model.SitecoreHome>();

Label4.Text = "<br> This is ---" + home.PageTitle + "----" + home.Created.ToString() + "---" + home.CreatedBy ;

Use LINQ with Glass

Create NotFound page for 404 error in Sitecore

Create template, layout and content for Notfound page.
Changes in web.config file
<setting name="ItemNotFoundUrl" value="/Notfound.aspx"/>
<setting name="LayoutNotFoundUrl" value="/Notfound.aspx"/>
<setting name="LinkItemNotFoundUrl" value="/Notfound.aspx"/>
<setting name="NoLicenseUrl" value="/Notfound.aspx"/>


In Notfound.aspx page write below code
protected void Page_Load(object sender, EventArgs e)
{
Response.Status = "404 Not Found";
Response.StatusCode = 404;
}

XslHelper - XSL extension methods in XSLT for Sitecore

Download “XslHelper.cs” from http://svn.sitecore.net/XslHelper/ and add it to project.
Open web.config file and find, comment and add below entry in <xslExtensions> tag
<xslExtensions>
      <extension mode="on" type="Sitecore.Sharedsource.Xml.Xsl.XslHelper, WebApplicationRND" namespace="http://www.sitecore.net/sc" singleInstance="true" />
      <!--<extension mode="on" type="Sitecore.Xml.Xsl.XslHelper, Sitecore.Kernel" namespace="http://www.sitecore.net/sc" singleInstance="true" />-->


Where WebApplicationRND is project assembly name.

Image Gallery in Sitecore

Assign Placeholder in Template Standard value and set its properties – width, height, presentation, media folder [set parent folder so that all folder images will be fall under it.]
Remember that Image Gallery accepts images of the type .JPG, all others will at the moment just result in a grey screen. If you want to include all types of images then change below lines in “ImageGalleryXMLConfiguration.xslt” file


  <!--<xsl:if test="./item[@template='jpeg']">-->
  <xsl:if test="./item">
    <album title="{@name}"
           description="{sc:fld('description',.)}"
           image="{sc:fld('image',.,'src')}">
      <!--<xsl:for-each select="item[@template='jpeg']">-->
      <xsl:for-each select="item">

Create and fill table in SQL server from XML file

<?xml version="1.0" encoding="UTF-8" ?>
<Dealers>
  <Dealer id='77'>
    <Dealer_Address>
      <Name>Action Kia</Name>
      <Address>Cnr Bruce Highway And Oak St</Address>
      <Suburb>Gympie</Suburb>
      <State>QLD</State>
      <Postcode>4570</Postcode>
      <WorkPhone>(07) 5482 2759</WorkPhone>
      <Opening_Hour>Mon-Fri: 8:00 AM-6:00 PM-br-Sat: 8:00 AM-12:00 PM-br-Sun: Closed</Opening_Hour>
      <Fax>(07) 5482 2389</Fax>
      <Url>www.actionautogroup.com.au</Url>
      <Email></Email>
      <Longitude>152.650454</Longitude>
      <Latitude>-26.179577</Latitude>
    </Dealer_Address>
    <Service_Address>
      <Name>Action Kia</Name>
      <Address>Cnr Bruce Highway And Oak St</Address>
      <Suburb>Gympie</Suburb>
      <State>QLD</State>
      <Postcode>4570</Postcode>
      <WorkPhone>(07) 5482 2759</WorkPhone>
      <Opening_Hour>Mon-Fri: 8:00 AM-6:00 PM-br-Sat: 8:00 AM-12:00 PM-br-Sun: Closed</Opening_Hour>
    </Service_Address>
  </Dealer>
  <Dealer id='7'>
    <Dealer_Address>
      <Name>Adtrans Kia</Name>
      <Address>1178 - 1184 South Road</Address>
      <Suburb>Clovelly Park</Suburb>
      <State>SA</State>
      <Postcode>5042</Postcode>
      <WorkPhone>(08) 8374 2744</WorkPhone>
      <Opening_Hour></Opening_Hour>
      <Fax>(08) 8374 2755</Fax>
      <Url>www.adtranskia.com.au</Url>
      <Email></Email>
      <Longitude>138.574837</Longitude>
      <Latitude>-34.997404</Latitude>
    </Dealer_Address>
    <Service_Address>
      <Name>Adtrans Kia</Name>
      <Address>1178 - 1184 South Road</Address>
      <Suburb>Clovelly Park</Suburb>
      <State>SA</State>
      <Postcode>5042</Postcode>
      <WorkPhone>(08) 8374 2744</WorkPhone>
      <Opening_Hour></Opening_Hour>
    </Service_Address>
  </Dealer>
</Dealers>

SELECT
      product.value('../@id', 'int') as id,
      replace(X.product.query('Name').value('.', 'VARCHAR(300)'), 'And', '&') as Name,
      X.product.query('Address').value('.', 'VARCHAR(300)')as Address,
      X.product.query('Suburb').value('.', 'VARCHAR(300)')as Suburb,
      X.product.query('State').value('.', 'VARCHAR(300)') as State,
      X.product.query('Postcode').value('.', 'VARCHAR(30)') as Postcode,
      X.product.query('WorkPhone').value('.', 'VARCHAR(20)') as WorkPhone,
      replace(X.product.query('Opening_Hour').value('.', 'VARCHAR(300)'), '-br','<br>') as Opening_Hour
INTO Service_Address
FROM
(
      SELECT CAST(x AS XML) FROM OPENROWSET(BULK 'D:\dealers_2012125 - Copy.xml', SINGLE_BLOB) AS T(x)
) AS T(x)

CROSS APPLY x.nodes('Dealers/Dealer/Service_Address') AS X(product);

Photoshop useful commands

Select – Control + Mouse click
Copy – Control + shift + C
New - Control N
Save as image size – control + shift + alt + S
Enlarge - Control + space + mouse click

Deselect all items – Control + D