Surendra Sharma

Surendra Sharma

Search This Blog

Tuesday, February 3, 2015

Script for LuckyOrange tracking code

Like Google Analytic, there are other analytic support available on web. One of them is #LuckyOrange

To work with this you need Site ID. I represented it in sample code as “NNNNN”. Below is script that you need to place it between <head> </head> section of webpage. The code is asynchronous and will not block your page from loading.

<script type='text/javascript'>
    window.__wtw_lucky_site_id = 'NNNNN';

    (function () {
        var wa = document.createElement('script'); wa.type = 'text/javascript'; wa.async = true;
        wa.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://cdn') + '.luckyorange.com/w.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(wa, s);
    })();

</script>


Please leave your comments or share this code if it’s useful for you.

Monday, February 2, 2015

How to attach or execute batch file with Visual Studio Build process

There are some scenario in project development when one need to execute some EXE or batch file after successful Visual Studio build process.

Question is how to do that?

Here is a way

Create sample batch file and save it. Note down the complete batch file path suppose it’s “D:\ShareForAll\My Batch File.bat”. Follow below steps to attach it to Visual Studio.

·         Now open Visual Studio project.
·         Right click project in solution explorer and select Properties
·         Click on Build Events
·         Enter commands in Post-build event command line as in below image
o    You can enter any DOS command here.
o    To execute Batch file, write call “<filepath.bat>”





Please leave your comments or share this tip if it’s useful for you.

Sunday, February 1, 2015

How to download outlook calendar file from ASP.Net website

Sometime we need to show schedule of some events on website and allow user to download the calendar for outlook which user can save in their local computer or allow them to directly open it in outlook.

The trick here is same to write the code for downloading any file from response, only thing to remember is the calendar content and content type “text/calendar”.

Here is the code

        protected void Button2_Click(object sender, EventArgs e)
        {
            System.Text.StringBuilder sbICSFile = new System.Text.StringBuilder();
            DateTime dtNow = DateTime.Now;

            sbICSFile.AppendLine("BEGIN:VCALENDAR");
            sbICSFile.AppendLine("VERSION:2.0");
            sbICSFile.AppendLine("PRODID:-//ICSTestCS/");

            sbICSFile.AppendLine("BEGIN:VEVENT");
            sbICSFile.AppendLine("DTSTART:20120515T110000Z");
            sbICSFile.AppendLine("DTEND:20120515T113000Z");
            sbICSFile.AppendLine("UID:1");
            sbICSFile.AppendLine("DESCRIPTION:Test Desc");
            sbICSFile.AppendLine("SUMMARY:calander");
            sbICSFile.AppendLine("END:VEVENT");
            sbICSFile.AppendLine("END:VCALENDAR");

            Response.ContentType = "text/calendar";
            Response.AddHeader("content-disposition", "attachment; filename=CalendarEvent1.ics");
            Response.Write(sbICSFile);
            Response.Flush();
            Response.End();
        }

  
Please leave your comments or share this code if it’s useful for you.

Thursday, November 13, 2014

How to access or connect internet from laptop to mobile

I was just looking a way to share my laptop internet with my android mobile or more specifically I was trying to make my laptop into wifi hotspot.

First I tried to create ad hoc network from control panel but somehow that didn't worked.

Then I thought to take help of some third party utilities to make wifi hotspot.

I googled and tried Connectify but somehow it didn’t worked for me and second thing its paid.

I again googled for some free tool and come up with mHotspot.

I installed it. Filled some basic information into the window and it started to work on my laptop.

The most important think I liked about this tool is its completely free, small size and simple UI.

You can connect any internet connection to your laptop like USB dongle, wifi or wired cable and this app make your laptop into WIFI Hotspot.

Here is a link to download mHotspot.

Once your laptop become WIFI hotspot, turn your mobile wifi ON and connect to laptop hotspot.

If you are unable to access internet even after connecting to Hotspot, here is way to fix the problem.

Huuurrrryyy, now my mobile start to use internet through my laptop.

Thanks mHotspot.


Please leave your comments or share this tip if it’s useful for you.

Tuesday, November 4, 2014

How to directly insert new content item from a specific template in Sitecore

Everything in Sitecore is item. Most important is content items.

There are scenarios when we want to force content editor to insert new content item from a specific template. For example, we want to insert only Country specific pages under World content item as shown below

·         Home
o    World
§  India
§  US
§  China
§  Egypt

How to do it in Sitecore?

For this create two template in Sitecore – for example World and Country with their standard values as shown below




There are no fields in World template. However you can keep any fields if you need.

Select Standard Values of World template -> Select Configure Menu -> Click on Assign under Insert Options section -> from Insert Option window assign Country template -> Ok




Now insert World content item under Home. Under this World item we have option to insert directly country specific items as shown below



Insert some more Country items under World items. So finally we come up with hierarchical structure as shown below



Please leave your comments or share this tip if it’s useful for you.

Friday, October 31, 2014

How to map Visual Studio web project to Sitecore

Once you installed Sitecore then next step is to create and map your Visual Studio Web project to Sitecore.

It’s good to install software in sequence of IIS, SQL Server, Visual Studio and then finally Sitecore.

For this tutorial we will create Welcome page in Visual Studio and show Welcome <Employee Name> message where Employee Name should retrieve from Sitecore Content item. Final screen should look like



My Sitecore instance is running at “C:\inetpub\wwwroot\NewInstance2\Website” and I will create my visual studio project at “D:\MyTestApp”.

So we have all the necessary details. Let’s do mapping now.

Here are steps to map your project with Sitecore.

1.    Create ASP.NET Empty Web Application project in C# having name like “SitecoreWebApp” as below



2.    Delete Web.config file from newly created project.
Add folders like “layouts”, “sublayouts”, “upload” and “xml” to this application.
Add “welcomepage.aspx” page in layouts folder.
Copy “Sitecore.Kernel.dll” from Sitecore instance [i.e. from C:\inetpub\wwwroot\NewInstance2\Website\bin] to project bin directory [i.e. to D:\MyTestApp\SitecoreWebApp\SitecoreWebApp\bin] through file system.
Add reference of this “Sitecore.Kernel.dll” to current project and set its property CopyLocal = false.
After all these steps your solution should look like this



3.    Login to Sitecore and create “Employee” template as below



4.    Also create standard values for this template by selecting Employee Template -> Select Builder Options Menu -> Click Standard Values as below



5.    Enter token in Employee Name field as “$name” so that content item name should filled by default as below



6.    Create Layout having name “welcomepage” as below



7.    Create content item with name “Surendra Sharma” as below. Check Employee Name field filled automatically as per the item name.



8.    Our content is ready but we need layout to display this information. So map this content with layout by selecting content item “Surendra Sharma” -> Presentation Menu menu -> Details -> Click Edit link from Default section -> Select Layout -> Select “Layouts\welcomepage” as below



9.    Now go to Visual Studio project and design and code “welcomepage.aspx” page as below





10. Till this step we mapped everything. It’s time to publish our Web application from Visual Studio. So right click your project from Solution Explorer and select Publish. Create profile and select publish method as “File System”. Select Target Location as your Sitecore instance website folder. In my case it is “C:\inetpub\wwwroot\NewInstance2\Website” as shown below



11. In next step select Release configuration only and uncheck Delete checkbox as shown below



12. After successful publishing, we can Preview the content item. So select “Surendra Sharma” from content tree -> Publish Menu -> select Preview as shown below



13. Your browser should show screen like this



14. Bazinga!!!! Congrats, if you are reading this line, you successfully mapped your project with Sitecore.


Please leave your comments or share this guide if it’s useful for you.

Thursday, October 30, 2014

How to install multiple web instances of Sitecore on single machine

If you want to work on multiple Sitecore projects then it’s a tricky situation to install and run multiple Sitecore instances on the same machine.

If you don’t know how to install Sitecore, then please refer my previous article on it from here.

First install as many sitecore instances you want. At my machine I installed 3 instances of Sitecore as NewInstance1, NewInstance2 and NewInstance3.

I had used same License.xml file during installation of all instances.

After installation, my IIS and SQL Server should look like this



For each instance, there are 3 databases.



·         If you want to browse and run all instances at the same time then there must be valid entry in “hosts” file at “C:\Windows\System32\drivers\etc” for each instance as shown below



If you did not find any such entry in Hosts file then make it manually.


Please leave your comments or share this tip if it’s useful for you.