Saturday 8 November 2014

Reading values from an Sitecore Item

Reading values from an Sitecore Item

string fieldValue;
  
//Option 1: Getting the fieldvalue directly
fieldValue = Sitecore.Context.Item["MyField"];

 //Option 2: Getting the field and then reading the value
Sitecore.Data.Fields.Field myField = Sitecore.Context.Item.Fields["MyField"];
if (myField != null)
  fieldValue = myField.Value;

Retrieving Sitecore items

Retrieving Sitecore items

All items are accessed through the Sitecore.Data.Items.Item class

You are mostly going to get an instance of an item through the Sitecore.Data.Database class. This allows you to retrieve items normally by specifying a path or an ID. Like this:

//Get the master database through a Factory
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
   
//Retrieving an item with a path through the database
Sitecore.Data.Items.Item myItem = masterDb.Items["/sitecore/content/home"];
  
//Retrieving an item from an item id

Sitecore.Data.Items.Item mySecondItem = masterDb.Items[newID("{BB07A18A-580D-4105-9A1D-F3072D1A0BE3}")];

Sitecore Tokens

Sitecore Tokens


By default there are the following tokens available in Sitecore:
$name: Is replaced with the name of the created item
$parentname: Is replaced with the name of the parent to the created item
$date: Is replaced with the current date
$time: Is replaced with the current time
$now: Is replaced with current date and time
$id: Is replaced with the id of the created item
$parentid: Is replaced with the id of the parent to the created item

Wednesday 5 November 2014

CONFIGURE VISUAL STUDIO 2012 PROJECT FOR SITECORE (v6.4 to v7.5)

CONFIGURE VISUAL STUDIO 2012 PROJECT FOR SITECORE (v6.4 to v7.5)


Steps to configure VS 2012 for Sitecore  (v6.4 to v7.5)

In Visual Studio 2010, to create a project and solution for a Sitecore installation:

  1. Open VS 2012
  2. Click File >> New >> Project :
  3. In the New Project dialog, select .NET Framework 4.5, 
  4. Select the ASP.NET Empty Web Application project model 
  5. Set Name to the name of the project (ProjectName), 
  6. Set Location to the path to the WebSite folder for the project (C:\inetpub\wwwroot\ProjectName\WebSite) 
  7. Uncheck >> the Create directory for solution checkbox
  8. Click OK.
  9. In Visual Studio, click File >> Close Solution.
  10. Move the Properties folder, the .csproj file, and the .csproj.user file from the subdirectory created by Visual Studio (C:\inetpub\wwwroot\ProjectName\Website\ProjectName) to the WebSite subdirectory (C:\inetpub\wwwroot\ProjectName\Website). 
  11. Delete the subdirectory created by Visual Studio (C:\inetpub\wwwroot\ProjectName\Website\ProjectName).
  12. Open Visual Studio and open the newly created .csproj file.
  13. In Visual Studio, delete the /Web.config/Web.Debug.config and the /Web.config/Web.Release.config file from the project.
  14. In Visual Studio, add references to /bin/Sitecore.Client.dll, /bin/Sitecore.Kernel.dll, and any other dependent assemblies that you use in every project. 
  15. Set the Copy Local property to false for each reference to an assembly in the /bin folder.
  16. In Solution Explorer double-click Properties, set a default Assembly name and a Default namespace, and select the appropriate .NET framework version for your version of Sitecore.
  17. To use the /layouts subdirectory and/or the /xsl subdirectory, Go to Solution Explorer, select the project, and then click the Show All Files button. 
  18. Right-click on each relevant subdirectory and then click Include In Project, 
  19. Right-click each of the individual subdirectories and files in that subdirectory and click Exclude From Project. Remember to clear the Show All Files button afterwards, or debugging from Visual Studio could fail.
  20. After build or while closing project, Visual Studio will prompt you to create a solution for the project. Save it as your choice.
Enjoy.......VS2012 with Sitecore...................