Rajesh kumar’s Blog

If you have knowledge, let others light their candles at it.

Author Archive

Qualities of an Innovator

Posted by Rajesh Kumar on October 11, 2012

1. Challenges Status quo

  • Dissatisfied with current state.
  • Questions Routine.
  • Confronts assumptions.

2. Self-motivated

  • Finds reason and Strengths to complete a task.
    Technorati Tags:
  • Intrinsically rewarded for efforts.

3. Curious: Explores environment

  • Investigates new possibilities.
  • Honors sense of awe and wonder.

4. Takes Risks: Go beyond comfort zone.

  • Experimental and non-conforming.
  • Courageously willing to fail.

5. Tolerates Ambiguity:

  • Comfortable with chaos.
  • Doesn’t settle for the first “RIGHT IDEA”.

6. Committed to Learning

  • Continually seeks knowledge.
  • Synthesizes new input quickly.
  • Balances information gathering and action.

7. Recognizes Patterns

  • Notices organizing principles & trends.
  • Sees and challenges the “BIG PICTURE”.

8. Formally Articulate

  • Communicates ideas effectively.
  • Translates abstract concepts into meaningful language.
  • Creates prototypes with ease.

9. Flexible/Adaptive

  • Open to coincidence and change.
  • Able to adjust game plan.
  • Entertains multiple ideas & solutions.

10. Resilient

  • Bounces back from disappointment.
  • Learns quickly from feedback.
  • Willing to try again.

11. Makes New Connections

  • Sees relationships between seemingly disconnected elements.
  • Synthesizes new combinations.

12. Self-accepting

  • Withholds compulsive criticism of their own ideas.
  • Understands “If you seek perfection, you will never be content”.

Posted in General | Leave a Comment »

Create non zero indexed arrays in C#

Posted by Rajesh Kumar on December 19, 2011

99.99% of the time, we write our code with zero indexed arrays. However, C# allows us to create non zero based (single or multi dimensional arrays).

The syntax from MSDN is:

public static Array CreateInstance(   
                Type elementType,   
                int[] lengths,
                int[] lowerBounds)

CreateInstance is a static method available in Array class. Here, variable "lengths" indicates the dimension of the array and "lowerBounds" indicates what is the starting lower bound of each dimension array.

To understand the concept in a simple way, let’s consider the single dimension array and the following code is used to create the instance

// Create the instance of an Array   
Array myArray = Array.CreateInstance(typeof(int), new[] { 4 }, new[] { 2011 });
// Set the values to array  
myArray.SetValue(5, 2005);   
myArray.SetValue(6, 2006);   
myArray.SetValue(7, 2007);   
myArray.SetValue(8, 2008);   
// Display the lower bound of the array  
// Display the upper bound of the array  
// Display all the items in the array  
for (int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++)  


1. More meaningful index, based on scenario.


  1. Slow performance.
  2. Non CLS complaint.

Posted in .Net | Tagged: , , | Leave a Comment »

Display HTML content through ASP.Net MVC with Razor view engine

Posted by Rajesh Kumar on August 26, 2011

In this post, I will show you how to display HTML text on web page through an ASP.Net MVC application with Razor as the View Engine. The goal is to read file content from a specified location and display on web page.


Visual Studio 2010
ASP.Net MVC3 (

Let’s first create a new MVC3 project. Please follow the below steps to do so:

1. Open Visual Studio 2010.

2. Click on Create Project and select ASP.Net MVC3 template. Give any project name that you prefer and click on Next.


3. Chose the options as Intranet application. View engine as Razor. Select Html5 option.


4. Once you click on Ok, you will see the project structure as shown below:


5. When you run the application without make ANY changes, you will be able to see a home page with the welcome message.

6. Let’s wipe out default messages as we don’t need them at all. To change the application title, move to Views –> Shared folder, double click on _Layout.cshtml page to open.

7. In body section, change the “My MVC Application” to “Log Viewer application”.

8. Let’s create the model now that holds the file names list and selected file content. To do this, right click on “Model” folder, select Add –> New class option. Give the name as “LogFileModel” and select Ok button. Add the following code:

public class LogFileModel
    public List<SelectListItem> NamesList { get; set; }

    public string SelectedFileName { get; set; }

    public string SelectedFileContent { get; set; }

The important point to consider here is [AllowHtml]. This attribute allows us to display the HTML content.

9. For this example, let’s assume that we want to display the files information on the “Home” page itself. So, let’s go to HomeController. Please remember that ASP.Net MVC strictly follows naming conventions. The prefix of “Controller” represents the action that we are trying to perform. Here, “Home” represents, we want to display “Home” page (Index is the alias name).

10. Another important point is, ASP.Net MVC is a stateless application. It does not maintain View state. So, if we want to differentiate between normal page request and post back page request, we need to make use of other attributes such as “HttpGet” and “HttpPost”.

11. So, we want to do like this. When the page is requested freshly, we only display the list of files that are available in the specified folder. When the user selects the file and clicks on “View” button, we will get the HTML/text content from server and show on web page.

12. Let’s write the code to display list of files from selected folder as:

public class HomeController : Controller
   private LogFileModel _logFileModel;
   string directoryPath = @"C:\Log";

   public ViewResult Index()
        _logFileModel = new LogFileModel();
        _logFileModel.NamesList = GetLogFileNames();
// return data to View
return View(_logFileModel);

private List<SelectListItem> GetLogFileNames()
// Get the List of files
     // Order them by last write time
var fileNamesQuery = fromfile in newDirectoryInfo(directoryPath).GetFiles()
                         orderby file.LastWriteTime
                         select new
                              Text = file.Name,
                              Value = file.Name,

Here, we are trying to retrieve the list of files available in “C:\Log” folder and return to view as a list by populating it into our model class “LogFileModel” that we created earlier.

Note: Please make sure that there are some files available in Log files and is accessible to IIS users group.

13. Now, it’s the time to add dropdownlist and TextArea on web pages to hold the data.

14. Open the Index.cshtml file while is under Views –> Home folder and the following content:

    ViewBag.Title = "Home Page";
@model LogViewer.Models.LogFileModel

   @using (Html.BeginForm())
       <p>Log files: 
           @Html.DropDownListFor(x => x.SelectedFileName, Model.NamesList, "Choose the Log file")
           <input type="submit" value="View" />
   @Html.TextAreaFor(m => m.SelectedFileContent, 15, 105, new { @style = "resize: none;" }) 

15. Let’s try to understand Razor here…

ViewBag is like a Dictionary object that can be accessed and shared between View and Controller. We can pass data between these withit his.

@model LogViewer.Models.LogFileModel can be referred as a string type model binding to the view. With this, View (.cshtml) will be able to know which model it trying to speak to.

As we want to post back the page with the selected file, we need to encapsulate the HTML tags inside “form” tag. In Razor, we use it as Html.BeginForm().

@Html.DropDownListFor is used to display the list of files that are passed to View. When the user selects a file, its file name value will automatically be assigned to “SelectedFileName” property of “LogFileModel” object.

@Html.TextgAreaFor renders a “TextArea” control on web page to actually display the file content.

16. When we run our application now, you may see the UI as:


17. When you select a file and click on “View”, you will see no action. So, let’s handle that event now. To do this, go back to HomeController and add the following code:

public ViewResult Index(LogFileModel logFileModel)
    logFileModel.SelectedFileContent = System.IO.File.ReadAllText(Path.Combine( 
                                             directoryPath, logFileModel.SelectedFileName));
    logFileModel.NamesList = GetLogFileNames();
    return View(logFileModel);

18. Here, we are writing an overload method of Index that accepts our model class. We are also marking the method as [HttpPost] attribute. Another attribute [ValidateInput(false)] will stop validating the input. This allows us to display the HTML content without any problem. If this is not included, you can an error as “Potentially dangerous…”.

19. We are reassigning the FileNames list to the returning model object. We must do it as the ASP.Net MVC do not maintain ViewState.

20. That’s all. Our code is ready. Now, run the application, select the file and click on View button. You will be able to see the file content on web page.

Posted in ASP.Net MVC | 1 Comment »

Debug the .Net code from remote machine

Posted by Rajesh Kumar on July 11, 2011

Debugging the code from development environment is very easy. The actual problem starts when we want to debug the code that is already deployed in some system (local system, remote system, production server etc.).

It’s because, such environments will not have any SDK installed. However, Microsoft still makes developer’s life easier by allowing us to debug such deployed code from our local machine. This article tries to explain it.

Limitation: Visual Studio Professional, Premium and Ultimate versions can be used to debug the code. Visual studio Express does NOT allow you to debug the code through a process.

What needs to be done?

We need to do two things for debugging from remote machine:

  • Preparing remote system.
  • Attach the deployed code to source code from local machine.

What are required?

We need two things to start the remote debugging:

  • PDB files
  • MSVSMON.exe
  • You must have access to the remote system.
  • Your remote and local system must be in same domain (or in trusted domain list).

If you are not sure what are pdb files, A program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program. A PDB file is created when you build with /debug. (extracted from MSDN).

MSVSMON (Microsft Visual Studio remote debugging monitor) acts as an agent from remote system for Visual Studio. It comes with SDK installation and is generally available at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe. (x64 indicates your operating system mode).

The most important point to remember is, we must have the same version of PDB files of the original source code deployed on remote machine. Please read this article for more information.

Preparing remote system:

Please feel free to copy the entire x64 (as mentioned above) to the remote machine where the code is deployed and run the msvsmon.exe file. You may see the screen as given below:


Now, move all .pdb files to the bin directory of the deployed application. Now, it’s the time to identify the process id of the application that you want to debug. Task Manager shows list of processes running on the current (remote)and its Ids against them. It is very straight forward for finding process Ids for services or exe files. However, it is bit different for web application. Please read my article here to find out more.

Attach the deployed code to source code from local machine:

Open the source code in Visual Studio. Go to “Debug –> Attach to Process” option. You should be able to view “Attach to Process” window.

Leave the “Transport” to Default. In the “Qualifier” text box, type the text as <DomainName\UserName@ServerName> as displayed in msvsmon.exe window given above and then hit Enter key.

With this, Visual studio makes the connection to remote system and gets all processes list running on remote machine. You may see the screens in local machine and remote machine as below:

image image

Now chose, the right process Id and hit “Attach” button. With this, you are ready to debug the code. Happy debugging Smile.

References: MSDN

Posted in .Net, Debugging, IIS, Visual Studio | Tagged: | 4 Comments »

Remote Desktop Connection Manager

Posted by Rajesh Kumar on July 9, 2011

If you are working with multiple remote desktop and feeling uncomfortable with regular “Remote Desktop Connection” tool, then you can try with “Remote Desktop connection Manager” from Microsoft. It is free, very light weight, allows you to configure multiple remote desktop and can connect to all of them one-by-one or all at once.

You can download this tool at: http://www.microsoft.com/download/en/details.aspx?id=21101


Posted in Uncategorized | 1 Comment »

Find Process Ids for web sites running under IIS 6

Posted by Rajesh Kumar on December 10, 2010

During the debugging, you can attach the current code from Visual Studio to hosted web service or application. This helps to debug the code in Visual Studio while requests are coming to IIS web service or application. However, this is possible only when you know the Process Id.

The below command display the list of process ids running under IIS:

cscript %systemroot%\system32\iisapp.vbs

You can get the result as:


Posted in IIS | 1 Comment »

Access Team Foundation Server through webs ervices

Posted by Rajesh Kumar on October 21, 2010

Team Foundation web Services comes in two flavors V1.0, and V2.0, perhaps for backward compatibility with Team Explorer 2005 as given below:

Build Service







Services Service









Version Control Service




Warehouse Service

WorkItem Tracking Service





Posted in Team Foundation Server | 1 Comment »

WCF useful links

Posted by Rajesh Kumar on June 29, 2010

WCF – http://msdn.microsoft.com/en-us/netframework/aa663324.aspx
(.net Framework Developer center, central resource for all things WCF)

WCF 3.5 samples – http://msdn.microsoft.com/en-us/library/ms751514.aspx
WCF 4.0 samples – http://msdn.microsoft.com/library/dd483346(VS.100).aspx
(good resource to learn the basics by playing with samples)

WCF screencasts – http://msdn.microsoft.com/en-us/netframework/wcf-screencasts.aspx

.Net endpoint blog – http://blogs.msdn.com/endpoint/
(Blog by the .NET and AppFabric teams about WCF and WF development, deployment, and management)

Bug report/ Feature request/ Feedback to the product team – https://connect.microsoft.com/wcf
(There are useful resources mentioned at the bottom of this page as well)

Detailed WCF security guidance –http://www.codeplex.com/WCFSecurity

Detailed debugging using WCF tracing – http://msdn.microsoft.com/en-us/library/ms733025.aspx

Posted in WCF | Leave a Comment »

Enable https on Silverlight application

Posted by Rajesh Kumar on June 18, 2010

The following steps can allow you to convert http based silverlight application to https:

Changes required in web.config at service side:

1. Replace “mexHttpBinding” with “mexHttpsBinding”.
2. Remove “identity” node from “endpoint”.
3. Replace “httpGetEnabled” with “httpsGetEnabled”.
4. Make sure that clientaccesspolicy and crossdomain files are at the root of the website.

Changes required in ServiceReferences.Clientconfig at client side:

1. Replace security mode “None” with “Transport”.
2. Point to right https URL.

Posted in Uncategorized | Leave a Comment »

Compare WCF with other Technologies

Posted by Rajesh Kumar on April 20, 2010

The below diagram (extracted from Microsoft web) gives us the comparison of WCF with other services:

Posted in .Net, WCF | Leave a Comment »