Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Thursday, April 23, 2015

How to create error page in Sitecore


In every Sitecore application, you have to create error page. Error can be occurred at any time anywhere in application [We developers are always right. Errors are always due to incorrect contents entered by content editor J].

Anyway here are the steps to implement it

·         Create template, layout and content item for error page. I am creating only two fields in template here – Error Title, Error Message
·         On error page, I am displaying information of both these fields entered by content tree.
·         Generally I am creating single layout for all the contents. So I implemented the Page_Error event to capture all the error generated at layout page level.
·         Here is code

/// <summary>
/// page-level exception handler
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Page_Error(object sender, EventArgs e)
{
    // retrieve the last exception
    Exception exception = HttpContext.Current.Server.GetLastError();

    // handle any exception
    if (exception != null)
    {
        string error = exception.ToString();
        HttpContext.Current.Server.ClearError();
        ErrorLog(error);
    }
}

/// <summary>
/// Log and redirect to error page
/// </summary>
/// <param name="error"></param>
private void ErrorLog(string error)
{
    // log and clear the exception
    Sitecore.Diagnostics.Log.Error(error, this);
    // Pass the error on to the Generic Error page   
    string errorPageURL = Sitecore.Links.LinkManager.GetItemUrl(Sitecore.Context.Database.Items.GetItem(new ID("{SSSS778C-JKHJ-SKSK-A01C-411E2028KKKK}")));
    Response.Redirect(errorPageURL);
}


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

Saturday, March 28, 2015

How to repeat particular string or char into certain number of times

I was writing a program for showing a tree structure in textbox. I was trying to concatenate tabs and spaces in string. Soon I realize that it’s a very tedious way to achieve the result. I thought that .NET is the Ocean and there must be some way to repeat the particular string or character certain number of times. For example if I have character ‘0’ and I want to display it 5 times on screen. 

How to do it?

FOR and FOR EACH Loops are common, but I need some more smart way do it.
Here are some ways that I found

int count = 5;
string str = "PEACE ";
char c = '0';

Console.WriteLine(String.Empty.PadLeft(count, c));     //Output- 00000

string result = new String(c, count);
Console.WriteLine(result); //Output- 00000

Console.WriteLine(new StringBuilder().Insert(0, str, count).ToString());   //Output- PEACE PEACE PEACE PEACE PEACE

First two only repeat characters while last way is to repeat string. Hope this help someone.

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

Tuesday, February 17, 2015

How to store WFFM data in SQL Server instead of SQLite database in Sitecore

When you install WFFM package, by default it store data in SQLite database.

Disadvantage with SQLite is that it creates the database on disk and it’s not centralized.
However Sitecore provides a way to store WFFM data in SQL server.

Here are the steps to do it.

·         Restore database in SQL server from “Website\Data\Sitecore_WebForms.bak
·         Change “Sitecore.forms.config” file in “Website\App_Config\Include” where comment SQLLite section and uncomment MS SQL section and put the new connection string for restored database as shown below

    <!-- DLINQ compatible data storage -->
    <!-- MS SQL -->
   
    <formsDataProvider type="Sitecore.Forms.Data.DataProviders.WFMDataProvider,Sitecore.Forms.Core">
      <param desc="connection string">user id=abc;password=xyz;Data Source=your DS;Database=dbname</param>
    </formsDataProvider>
   

    <!-- Oracle -->
    <!--
    <formsDataProvider type="Sitecore.Forms.Data.DataProviders.Oracle.OracleWFMDataProvider,Sitecore.Forms.Oracle">
      <param desc="connection string">user id=(user);password=(password);Data Source=(database)</param>
    </formsDataProvider>
    -->

    <!-- SQLite -->
       <!--
    <formsDataProvider type="Sitecore.Forms.Data.DataProviders.SQLite.SQLiteWFMDataProvider,Sitecore.Forms.Core">
      <param desc="connection string">Data Source=/data/sitecore_webforms.db;version=3;BinaryGUID=true</param>
    </formsDataProvider>-->


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

Saturday, February 14, 2015

How to make URL in lower case in Sitecore

Sometimes client requirement is to make all letters lower case of their website URL. It’s a good practice as all search engine provide better result with lower case URL.

How to do it in Sitecore with .NET?

Sitecore is smartly provide this facility by changing just one entry in web.config file. If you want make URL in lower case then keep lowercaseUrls="true" from <linkManager defaultProvider="sitecore"> section in web.config file as highlighted below


    <linkManager defaultProvider="sitecore">
      <providers>
        <clear/>
        <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel" addAspxExtension="false" alwaysIncludeServerUrl="false" encodeNames="true" languageEmbedding="asNeeded" languageLocation="filePath" lowercaseUrls="true" shortenUrls="true" useDisplayName="false"/>
      </providers>
    </linkManager>


Woooowww. No programming required J


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

Thursday, February 12, 2015

How to check your new or modification PAN request status online

I personally feel that most of the life related work should done online. Why to visit difference government and private offices, why to meet them personally, why to call them. For a common man it’s always a difficult to go to government office and do their tasks. Government people are always showing that they are busy even they don’t have no work. Common man is always frustrated with government offices and their babus. So I always prefer to do it online.

So here I am sharing my personal experience to do changes in PAN card and how to track the request online.

If you had applied for PAN card changes like name, DOB, signature, photo etc. then you can submit your request at Karvy. You have to fill a form and attached old PAN card copy, ID proof, address proof. Submit this form along with 105 Rs. In return they will provide a receipt which has acknowledgement number. From that acknowledgement track your request status from below link


Either enter Acknowledgement number or your personal detail. Click on SUBMIT button as shown in below image and you can get the status which should be either in process or completed.




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

Tuesday, February 10, 2015

Tip for how to check your Aadhaar- Gas linkage Status

To get subsidy on LPG gas cylinder. You need to link your Aadhar Card number with gas agency and bank.

If you had applied your Aadhar card linkage request at Bharat Gas and Bank then you can check the status at below link


Enter your Aadhar card or cell number and click on Proceed button. Check the status on the status screen as shown below




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

Tip for how and where to check status of any modification request of Aadhar Card

If you have applied for any information update request in Aadhar card like Name, mobile number, address, date of birth, email then you can check update status at below link


You have to enter your Aadhar number and URN and on click of Get Status button you can check the status.



Please leave your comments or share this tip 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.

Monday, September 8, 2014

Form 28 / Form no. 28 / No Objection Certificate (NOC)

Recently I want NOC from RTO for moving my vehicle. For that one need form 28. If it’s a state wise transfer then you need 3 copies of Form 28 for inter-state, we require 4 copies.

RTO in India is the perfect example of mismanagement. RTO Employees are worst and local agents are best. But I tried to get NOC from my own.

First problem I faced to get form 28. RTO office has form 28 copies but all are in Marathi. If you demand for English one then RTO employees show you the route of Xerox shop where shop guys selling it in 4 Rs.

You can even download form 28 from RTO website, but the worst thing is that it’s a 3 page PDF while actual form is only 2 pages which should be printed on both side of paper.

Here is scanned copy of form 28 that I got from Xerox guy.  Download it free and take a print. That’s it. No need to pay 4 Rs. to those greedy people.





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