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  ->

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


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();

    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;



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.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;

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

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