Blog

Weekly Archive – 24th July 2010

Below is the list of articles and blog post’s that I have done over the last week.

1. Use “Shift+Enter” to add “;” automatically at end of the line – Visual Studio 2010 Productivity Power Tool

Published Date :  July 21, 2010

2. “View this as root” – A Solution Navigator features in VS 2010 Productivity Power Tools

Published Date :  July 20, 2010

3. Unable to Start Web Site on IIS – “Process can not access the file because It’s being used by another process”. How to resolve ?

Published Date :  July 20, 2010

4. Bing Maps Silverlight Control Integration with SharePoint 2010 – Integration of Silverlight 4 with SharePoint 2010

Published Date :  July 19, 2010

Note : I will continue publishing this weekly archive with the list of all articles and post for that weeks  on every Saturday . I will also post a monthly archive after end of every month. This will give a quick summary of posts and article to all the readers.

Shout it

Use “Shift+Enter” to add “;” automatically at end of the line – Visual Studio 2010 Productivity Power Tool

Visual Studio 2010 Productivity power tools introduced many new features for VS developer. Here I am going to talk about one small but useful features of the productivity tool.   You can use “Shift + Enter” to add semicolon (;) to end of the line. Instead  of putting “;” end of the line, you just press “Shift+Enter”. It will automatically add “;” at the end of the line and will move the cursor to next line.

ShiftEnter

As shown in the picture. If you press “Shift+Enter” over there, power tool will automatically add “;” and the end and the cursor will be moved to next line.

MoveCursor

For more features please read following links :

http://weblogs.asp.net/scottgu/archive/2010/07/19/vs-2010-productivity-power-tools-update-with-some-cool-new-features.aspx

http://blogs.msdn.com/b/visualstudio/archive/2010/07/18/new-version-of-the-productivity-power-tools-is-available.aspx

Shout it

“View this as root” – A Solution Navigator features in VS 2010 Productivity Power Tools

Visual Studio 2010 productivity power tool introduced many new and interesting features with in the Visual studio 2010 which are really great for developer and will help all of us improve the productivity. You can download the Productivity tool from http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef .

Solution Navigator is a new window that has been introduced with in this power tool which is an enhanced Solution Explorer. This window having many features like search code, highlight code, code navigation, File open, save, edit status etc. Along with these features one of the interesting features that I liked is “View this as root”. This features is very much helpful when you have the many projects with in a solution or your solution hierarchy is large. To start “Solution Navigator” , go to View > Solution Navigator or use (Ctrl + W, F) as shortcut key.This will open the “Solution Navigator” window.

SolutionNavigator

Look and feel wise it is same as “Solution Explorer” but  functionally it is quite different. You will find a “icon” at the right to side with all the files/folder under that solution as shown in below picture.

Unable to Start Web Site on IIS – “Process can not access the file because It’s being used by another process”. How to resolve ?

I was trying to run one of my local IIS hosted site I got page not found error. I was quite surprised to see that error because the site was up and running few hours back. I opened the IIS and found that my Site Application was in stopped mode. I started the web application and got the error message displayed below

Problem : Error message “Process can not access the file because It’s being used by anther process”  while starting the web application from IIS.

Investigation and Resolution:  Earlier my web site was running on the default IIS port ( Port 80 ).  From the error message it’s clear that port 80 is being used by some other process or some one is blocking it.

Bing Maps Silverlight Control Integration with SharePoint 2010 – Integration of Silverlight 4 with SharePoint 2010

In this article I have demonstrated how we can integrate a Silverlight Application with SharePoint 2010. I have used Bing Maps Control for Silverlight as example.



Development Environment

I have used below development Environment for this application

1. Visual Studio 2010 Ultimate Edition

2. SharePoint 2010 Server

3. Silverlight 4.0 Toolkit

4. Bing Maps Silverlight Control SDK

Before starting development you have to install “Bing Maps Silverlight Control SDK” as a prerequisite. You can download the same from “Bing Maps Silverlight Control SDK” .Once you are done with the setup of Development environment the first thing you need to do is to register and create an account at https://www.bingmapsportal.com/ . Once you registered on bing maps portal, you need to provide below information to get an access key for using Bing Maps.

Identifying Worker Process (w3wp.exe) – IIS 6.0 and IIS 7.0 for Debugging ASP.NET Application

If you are debugging a ASP.NET web application which is hosted on IIS, you need to attach the particular worker process in Visual Studio to start debugging. To Attach a process we can go to Tools > Attach Process or use shortcut key Ctrl +P. The process window will show the worker process (w3wp.exe) which is currently running on IIS. You need to select the process and click on attach button to start the debugging.
Problem starts when you have multiple worker process running on IIS.  If you have multiple sites hosted on IIS and each site having their own application pool then you will see the list of all worker process in the Process Attach window.


Here  you need to identify the particular worker process which is associated with your application pool.

Note: Whenever we create a new Application Pool, the ID of the Application Pool is being generated and it’s registered with the HTTP.SYS (Kernel Level of IIS) . So whenever HTTP.SYS Received the request from any web application,  it checks for the Application Pool and based on the application pool it send the request

Custom web parts not getting displayed after deployment in share point 2010. how to resolve ?

In Share point 2010, we can create Visual Web parts very easily from Visual studio and can deploy it directly from Visual Studio. After deployment, when adding a web part on a sharepoint page you might face the issue that custom web parts are not getting displayed under custom web parts section though your deployment was successful from Visual Studio.

Fig :  No web parts after deployment

This problem might happen due to activation of features list of your corresponding web parts.  To resolved this issue you need to perform the following steps.

How to pass ASP.NET server side array to client side and binding them with Html element?

This is a very often requirement for an ASP.NET Developer to pass a sever side array to client side and access them through java Script. There are several ways to do that. But here I am describing one of the simplest steps to pass server side array to client side. In this blog post you will get to know two things, first one is the how to pass the array from server side to client side and second one is the how to bind that array to an empty “html dropdown” list.

Well, the easiest way to pass the server side array to a client side is  using  “RegisterArrayDeclaration” . RegisterArrayDeclaration method registers a javascript array with the System.Web.UI.Page Object. As the array object registered with the “Page” object so we can access it from javascript easily. RegisterArrayDeclaration takes array name and value of the array element as argument.

In below example, I have registered one array with name of “Skills”.

  protected void Page_Load(object sender, EventArgs e)
    {
       // Register List of Languages
        Page.ClientScript.RegisterArrayDeclaration("Skills", "'C#'");
        Page.ClientScript.RegisterArrayDeclaration("Skills", "'VB.NET'");
        Page.ClientScript.RegisterArrayDeclaration("Skills", "'C'");
        Page.ClientScript.RegisterArrayDeclaration("Skills", "'C++'");
    }

Now, what above declaration does?  This is nothing but a declaration of a java script array like,

Var Skills = new Array('C#', 'VB.NET','C','C++');

These “Skills” array is now only a JavaScript array which is easily accessible by client side code. Now Let’s have a look how to access them and how to bind them in a dropdown list.

How to update controls which are outside of updatepanel during partial page rendering?

we generally used update panel to do the partial page postback, which means to postback the controls which are only inside the update panel. For achieve this we simply call Update() method for the corresponding Update Panel. This thing is quite simple when we are trying to update any control which is inside the updatepanel itself. But, The problem may come when we want to update the controls which are outside of UpdatePanel and we need to update the same while updating then control inside updatepanel.

To make it simple. Let’s consider below scenarios. In our web page, we have Two labels (Label1 and Label2). Lable1 present inside the updatePanle and Label2 is in the outside of updatePanel. We have one Button say Button1, which is also inside the UpdatePanel. Now, our requirement is to update the Label2 while we are updating Label1 by Clicking Button1.

below is the code block for above scenarios

      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional>
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Button ID="Button1" runat="server" Text="Update Button"  onclick="Button1_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
     <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

Now, if we click on “Button1”, it will update only the content of Label1 not Lable2.

The solutions is to use ScriptManager.RegisterDataItem() . Using RegisterDataItem() methods we can register any control with the Particular Page ScriptManager Instance. While registering we need to provide the Control name along with the data item for the control which we want to render.

How to get list of all active HttpModules in ASP.NET?

Here is a quick tips to get the list of all active HTTPModules at runtime.  We can get the list of all HttpModules from the web.config or from machine.config file. But, what we need to do if we want to get the list of all active HttpModules during runtime? Yes. We can easily get the details with the help of  HttpApplication and HttpModuleCollection Class. If we quickly recall the IIS Process Request [One detailed Article], when a request reaches to worker Process from client browser, First of all Worker process is responsible to start and HttpRuntime by loading ISAPI filter. After that HttpRuntime load an HttpApplication object with the help of  HttpApplicationFactory class. Each and every request should pass through the corresponding HTTPModule to reach to HTTPHandler, this list of module are configured by the HTTPApplication. Below is the code snippet by which we can get the list of active HttpModules.

        //Get Application Instance from Current Content
        HttpApplication httpApps = HttpContext.Current.ApplicationInstance;
        //Get List of modules in module collections
        HttpModuleCollection httpModuleCollections = httpApps.Modules;
        Response.Write("Total Number Active HttpModule : " + httpModuleCollections.Count.ToString() + "</br>");
        Response.Write("<b>List of Active Modules</b>" + "</br>");
        foreach (string activeModule in httpModuleCollections.AllKeys)
        {
            Response.Write(activeModule + "</br>");
        }

Below is the sample output :

This can be quite useful when we want to check if our custom created  module loaded successfully or not .

Shout it

“CompressionEnabled” Session in ASP.NET 4.0

Session is the most important state management mechanism for a web application. In ASP.NET we are having two type of state management

1. In Process

2. Out Process

In process” is the by default session storage mode for ASP.NET Web application. When it comes under Out Process we can use either of state server or SQL Server to persist our session data.

Here I am going to describe one new features added in ASP.NET 4.0 realted with Session. If you want to know about when to use session, what session mode to use, how to configure the session storage please read one of my article “Exploring Session in ASP.NET” published at CodeProject.

In case of In Process, session data stored in In memory of worker process. But when we are talking about “OutProc” session mode, we need to ensure that session data should be “Serialized” first  . So, when we are moving session data from Web Server to Out Process Server ( State Server or SQL Server ) it can be a performance overhead based on the size of data that we are stroing in Session.

ASP.NET 4.0 comes us with a new option for compressing the Session data with Out Process Session mode. To enabling this functionality we need to add “compressionEnabled=”true” attribute with the SessionMode in web.config . Web.config entry would be look like below,

<sessionState mode="SQLServer" sqlConnectionString="Integrated Security=SSPI; data source=.;" <em>compressionEnabled="true" </em>allowCustomSqlDatabase="true">

This will compress / Decompress the session data during serialization / deserialzation of session data. ASP.NET 4.0 used System.IO.Compression.GZStream class to compress the session mode. One more important things to remember that use of compression mode is useful when we are storing large number of data in session because for every request it will going to use Gzip Compression/ Decompression going to be used to access the session variable.

Hope this will helps you !

Shout it

CSS Friendly Menu Control in ASP.NET 4.0


It is very much easier to apply CSS when we have ul,li elements as the HTML content. If we look into ASP.NET Menu Control till Version 3.5, its render as Table-TR-TD Tag. Though Table/Tr/Td is quite useful to display tabular data but sometime  creates  a big problem when we need to do more work with CSS. To overcome this problem we generally used CSS Friendly adapter to render the ASP.NET Control in ul/li mode.

ASP.NET 4.0 makes the things easier for web developer by providing “RenderingMode” properties. Here we can specify RenderMode of a ASP.NET Menu control. Which define the what will be the HTML Render Content Type. Bydefault mode is “List” which means control will be render as ul/li

As per the above diagram we can see that there are three mode available. We can use any one of them as per the requirement.

ViewState Control in ASP.NET 4.0


View State is one of the most important and useful client side state management mechanisms. It can store the page value at the time of post back (Sending and Receiving information from Server) of your page. ASP.NET pages provide the View State property as a built-in structure for automatically storing values between multiple requests for the same page.

we generally used “EnableViewState” Properties for both Page Level and Server Control Level to maintain the view state. Till ASP.NET 3.5 Version, Page Level view state control treat as highest priorities. Which means If we set EnableViewState= “False” in page level that will automatically derived by all the server side control. In that case if we set “EnableViewState=”True”” for any server side control will treat as false, as we have defined them “False” in Page Level.Here is one complete article on ASP.NET 2.0/3.5 View State , which may helpful for you

Now, let’s have a look into the changes in ViewState Control in ASP.NET 4.0. There is a massive change in View State Control in ASP.NET 4.0 which is very much helpful for developer also. Asp.net 4.0 added a new property to Page object and server controls called ViewStateMode.

IntelliTrace Debugging – Video Demo

Recently I have published one complete tutorial on Visual Studio 2010 Debugging. Which covered almost all main features of debugging in Visual Studio 2010 like Basic of Breakpoints,  breakpoint labeling, data tips, multithreaded debugging, and parallel debugging and IntelliTrace debugging. You can read the complete article from My Blog or from CodeProject.

While preparing the article I had created one small video on IntelliTrace Debugging which will show you the demo of using IntelliTrace Debugging.  Hope you will enjoy this video.

kick it on DotNetKicks.com