Sunday, November 17, 2013

Unable to launch the IIS Express Web server


I had exactly the same issue. Tried everything but finally one trick worked.
  1. Delete folder IISExpress from "My Documents"
  2. Load your project again, it will create IISExpress folder again with updated configuration
  3. Check IISExpress folder has sufficient permissions to read-write the configuration file
  4. Load project again and Run IISExpress. It should work.
Author: Sumit Bajaj

Thursday, October 24, 2013

Create dynamic content using Razor templates


This article is explaining the usage of Razor template and effectiveness of these templates.

Let's consider one scenario, when you have to send emails to different users with dynamic data which is different for different users. Example shown below is a basic example. Think of some complex scenario where plenty of data need to be changed and also require some styling.

To start work on one simple example, right click on your website folder and create a new blank @view. Name it as "Useremail.cshtml". Paste the mentioned code there.

Useremail.cshtml

   <html>
   <body style="font-familyArialfont-sizesmaller">
   <p>Dear @Model.Name,</p>
    <p>A new account has been created for you to access Application with                            username: <b>@Model.Username </b></p>
    <p>You can access the application at @Model.AppUrl.</p>
    <p>Your password will be sent to you in a following email.    </p>
    <p>Thank you,</br>
       Cleansheet Team.
    </p>
    </body>
    </html>


Explanation: The Useremail.cshtml is Razor template file which is having dynamic html. The variable which need to be dynamic, we can give them as @Model.variable_name. ( For example: @Model.Name )

Next step is to create Controller which will assign the dynamic values, given in Razor template.

Controller.cs

       var userTemplate = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory +                                     @"Views\Email\Username.cshtml");

       dynamic userObj = new { Name = "Sumit Bajaj", Username = "sbajaj", AppUrl =                                  Request.RequestUri.GetLeftPart(UriPartial.Authority) };

       string userMsg = Razor.Parse(userTemplate, userObj);
       Email.Send(user.Email, "Your user name for the Application", userMsg);


Explanation: File.ReadAllText is reading the template file from current base directory. userObj is dynamic object  which is being populated with variables we defined in template file.

Line [string userMsg = Razor.Parse(userTemplate, userObj);] is filling the userObj data in userTemplate (Razor template). Next line is sending email to user with dynamic data populated.


Razor class is part of RazorEngine assembly which can be downloaded from Download RazorEngine Assembly. You can add reference of this assembly in your website and use it.



~~ Happy Coding ~~




Wednesday, September 25, 2013

Nuget Error: "No more data is available"

Unable to install Nuget Package Manager on Visual Studio 2010 SP1, Windows 7, 64 bit machine. When creating new MVC4 Project, getting Nuget Error "No more data is available".

Here are the steps which will resolve the issue.

1. Open Visual Studio -> Tools -> Extension Manager...


2. From Online Gallery, Download Nuget Package Manager


If you get error like "No more data is available", Download it from Nuget Website.

3. Once downloaded, change the extension "vsix" to "zip"
    For example:  Nuget.Tools.vsix  -> Nuget.Tools.zip


4. Goto path
  C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\ide\Extensions\Microsoft Corporation\NuGet Package Manager\1.6.21205.9031

if it is not existing, create the folders so path could look like above path.

5. Unzip the Package (see step 3) in the folder (see step 4)

6. Now ...\NuGet Package Manager\1.6.21205.9031 should have all dlls and respective files

7. Restart Visual Studio and now it should work

Enjoy!!




Monday, September 16, 2013

Steps to migrate from other CMS to Sitecore

Here are few easy steps to migrate the data from other CMS to Sitecore

1. Get the detail of CMS from where to migrate in Sitecore

2. Export the articles or items in xml format. Generally all CMS gives this option to export it in xml file format

3. Read the xml tags one by one to get all related details (code given is just for reference)




//Get all files under specific directory
string[] files = Directory.GetFiles(path);

List<ArticleData> articleList = new List<ArticleData>();

//Read each file one by one
foreach (string filePath in files)
{
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(filePath);             

    ArticleData article = new ArticleData();
    article.FileName = filePath.Substring(path.Length + 1, (filePath.Length - (path.Length + 1)));

    XmlNodeList list = xmlDoc.SelectNodes("record/item[@name='it_article_title']");               
    article.Title = list[0].InnerText;

    XmlNodeList list1 = xmlDoc.SelectNodes("record/item[@name='it_publication_date']");               
    article.Date = list1[0].InnerText;

    XmlNodeList list2 = xmlDoc.SelectNodes("record/item[@name='it_author']");               
    article.Author = list2[0].InnerText;     

    XmlNodeList list4 = xmlDoc.SelectNodes("record/item[@name='it_summary']");               
    article.Summary = list4[0].InnerText;
   
    XmlNodeList list6 = xmlDoc.SelectNodes("record/item[@name='it_image_file_name']");               
    article.Thumbnail = list6[0].InnerText;

    articleList.Add(article);

}
           

4. Create template in Sitecore including all required fields

5. Take reference of below mentioned code to create item in Sitecore and fill the values in it


Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");

//Get the Item under which you want to import all items . 
//Here ID of that item is passed under which all items will be imported.
Item activeItem = masterDb.GetItem(new ID("1CD389F0-E0C7-4D22-A39D-0C5BD2A1251D"));                
//For Editing an Item in Sitecore, Security should be disabled else you have to create user //with required permission and write logic to authenticate it
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {  
                    Item newItem = activeItem.Add(article.FileName, template);
                    newItem.Editing.BeginEdit();
                    newItem.Fields["Title"].Value = article.Title;
                    newItem.Fields["Body"].Value = article.Text;
                    
                    DateTime dt = new DateTime();
                    DateTime.TryParse(article.Date, out dt);
                    newItem.Fields["Article Date"].Value = Sitecore.DateUtil.ToIsoDate(dt);

                    newItem.Fields["Image"].Value = article.Image;
                    newItem.Editing.EndEdit();
                }


6. Run the code and check, Item should be created in Sitecore

~~~~~~~~~~~~~~~Happy Coding !!~~~~~~~~~~~~~~

Thursday, June 20, 2013

Sitecore 7: The Power Packed

Sitecore 7 is new release of Sitecore content management system. It came up with so many exciting features that when someone will go through, definitely will say Wow!!. The industry's first fully integrated search based architecture.

Out of so many power-packed features, here is the list of few.

Search Boosting: It allows content to be pushed higher in the search. Rules are provided which can be easily created in sitecore depending on business requrements. For example: If we have 100 featured results to be displayed on page, then by boosting your items can up-rank it on top.



Dynamic Data: The nice change in Data source field. It allows to write query based data source which make it fully dynamic. 



Criteria can be written in Build Query dialog box.




Search Tagging: Inbuilt tagging mechanism pulls the content in search which is tagged. It is used for fetching more accurate data. No coding, its just add tags on item and you are done.

Big Data: There is no limit on the amount of content it can store. Good thing is that high volume of data is not impacting the performance in any way.

Pluggable Search: Everyone who worked on Sitecore has used Lucene/Solr but Sitecore 7 provides flexibility to plug search of your choice. 

User Interface is fully integrated with Search, LINQ usage and latest Microsoft.Net framework support and so many features to explore.


Wednesday, June 12, 2013

Importing existing blog data under New blog

Welcome to the topic 'Importing existing blog's data under new blog'. Generally people write new post in existing blog but few people write blogs in category. One kind of posts under one blog and other kind of posts under other blog. For example: java-script related posts under java-script blog, ruby related issues under ruby blogs.

Sometime when there is need to generate feed for blogs it gets difficult to accumulate all blogs under one feed when you have categories the blogs.

Those who have all posts under one blog, feeds get generated easily.

Let's see how different blogs can be grouped together under one blog. These steps are written for www.blogger.com, similar kind of steps can be used for other kind of blogging sites.

1. Open blogger.com and click on the blog which you want to move to other (main) blog
2. Click on Settings tab on left
3. Click on Other tab under Settings
4. Click on 'Export blog' which is shown on top right panel
5. Clicking on it will download the xml file, download it
6. Go back to main blog in which you want to import the blog
7. Follow the steps from 1-3 and click on 'Import blog'
8. Select the xml file which is downloaded and click on 'Import blog' button
9. Select the settings as you want and blog will be imported in main blog

Screenshot1 (Settings for existing blog) :
Importing blog



















Screenshot2 (Get Imported blog and import in main blog) :

















After importing when you will open the mail blog, you will find the imported blog is also coming in Blog Archive section. Click on that blog and verify if it is imported successfully.



















All the best and keep blogging !!

Thursday, March 28, 2013

Brightcove video event handling is way to capture the video events and perform some operations on occurrence of that event.


AlertNote: Brightcove API services does not work on local environment (for example: direct browsing of page) so you have to host the website on IIS.




Here are the steps to include video on page and capture the events and perform some action on event occurrence.

Open any HTML page and write the mentioned javascript code in head section.

Javascript Section

<script type="text/javascript">
         var player;
         var modVP;
         var modExp;
         var modCon;   
    
         function myTemplateLoaded(experienceID) {            
             player = brightcove.api.getExperience(experienceID);
             modVP = player.getModule(brightcove.api.modules.APIModules.VIDEO_PLAYER);
             modExp = player.getModule(brightcove.api.modules.APIModules.EXPERIENCE);
             modCon = player.getModule(brightcove.api.modules.APIModules.CONTENT);
             modExp.addEventListener(brightcove.api.events.ExperienceEvent.TEMPLATE_READY, onTemplateReady);
         }

         function onTemplateReady(evt) {        
             modVP.addEventListener(brightcove.api.events.MediaEvent.BEGIN, onMediaEventFired);
             modVP.addEventListener(brightcove.api.events.MediaEvent.CHANGE, onMediaEventFired);
             modVP.addEventListener(brightcove.api.events.MediaEvent.COMPLETE, onMediaEventFired);
             modVP.addEventListener(brightcove.api.events.MediaEvent.ERROR, onMediaEventFired);
             modVP.addEventListener(brightcove.api.events.MediaEvent.PLAY, onMediaEventFired);
             modVP.addEventListener(brightcove.api.events.MediaEvent.PROGRESS, onMediaProgressFired);
             modVP.addEventListener(brightcove.api.events.MediaEvent.STOP, onMediaEventFired);
         }


         function onMediaEventFired(evt) {
             alert(evt.type);
             if (evt.type === brightcove.api.events.MediaEvent.BEGIN) {
                 alert('Here Video Begins!!');
             }
         }
    </script>


Body Section


<div style="display: none"></div>

    <script language="JavaScript" type="text/javascript"src="http://admin.brightcove.com/js/BrightcoveExperiences.js">       
    </script>
    <object id="myExperience2128824061001"class="BrightcoveExperience">
        <param name="bgcolor" value="#FFFFFF" />
        <param name="width" value="480" />
        <param name="height" value="270" />
        <param name="playerID" value="PLAYED_ID" />
        <param name="playerKey" value="AQ~~,AAABywrPJyk~,MP34hwWOTrN8Z6UocoZHuAZdr8inViSF"/>
        <param name="isVid" value="true" />
        <param name="isUI" value="true" />
        <param name="dynamicStreaming"value="true" />
       
        <!-- smart player api params -->
        <param name="includeAPI" value="true" />
        <param name="templateLoadHandler"value="Test" />

        <param name="templateLoadHandler"value="myTemplateLoaded" />
        <param name="templateReadyHandler"value="onTemplateReady" />

        <param name="@videoPlayer" value="VIDEO_ID" />
    </object>