jump to navigation

Server.MapPath February 15, 2010

Posted by Bilal in .NET, APS, C#, Microsoft, Visual Studio 2005, Visual Studio 2008.
Tags: , , , , ,
add a comment

Server.MapPath specifies the relative or virtual path to map to a physical directory.

  • Server.MapPath(“.”) returns the current physical directory of the file (e.g. aspx) being executed
  • Server.MapPath(“..”) returns the parent directory
  • Server.MapPath(“~”) returns the physical path to the root of the application
  • Server.MapPath(“/”) returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)

An example:

Let’s say you pointed a web site application (http://www.example.com/) to the root of your domain


and installed your shop application (as virtual directory in IIS and marked as application) in


If, you call Server.MapPath in following request:



  • Server.MapPath(“.”) returns D:\WebApps\shop\products
  • Server.MapPath(“..”) returns D:\WebApps\shop
  • Server.MapPath(“~”) returns D:\WebApps\shop
  • Server.MapPath(“/”) returns C:\Inetpub\wwwroot
  • Server.MapPath(“/shop”) returns D:\WebApps\shop

If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path.

If Path doesn’t start with a slash, the MapPath method returns a path relative to the directory of the request being processed.

Note: In C#, @ is the verbatim literal string operator meaning that the string should be used “as is” and not be processed for escape sequences.

Source: Link

Some Visual Studio ShortCut Keys January 31, 2010

Posted by Bilal in .NET, Keyboard Shortcuts, Tips & Tricks, Visual Studio 2005, Visual Studio 2008.
Tags: , , ,



F3 Finds the next occurrence of the previous search text.
F5 Start debugging
F7 Jump to code behind file from .aspx files
F8 Moves the cursor to the next item, such as a task in the Task List window or a search match in the Find Results window. Each time you press F8, you move to the next item in the list.
F9 Toggle breakpoint
F12 Go to definition of identifier under cursor
Ctrl+F5 Start without debugging
Ctrl+F2 Jump to the Navigation Bar (hit TAB to get to the right side)
Ctrl+F3 Find word under cursor
Ctrl+TAB Toggle between windows in Visual Studio
Ctrl+I Incremental search (this is way better than Ctrl+F)
Ctrl+J Force IntelliSense for field members
Ctrl+C (with nothing selected) Copy whole line
Ctrl+Enter Open line above line cursor is on
Ctrl-X or Ctrl-L (with nothing selected) Cut whole line
Ctrl+] Bounce cursor between matching parentheses/brackets/braces
Ctrl+PageDown Toggle between Design and Source views in .aspx files
Alt+W, L Close all windows
Ctrl+K, Ctrl+C Comment out selection
Ctrl+K, Ctrl+U Uncomment selection
Ctrl+K, Ctrl+D Format document
Ctrl+K, Ctrl+X Insert snippet (or just type in the snippet name and hit TAB, TAB)
Ctrl+K, Ctrl+S Surround selected lines with snippet
Ctrl+K, Ctrl+K Toggle bookmark on/off
Ctrl+K, Ctrl+P Jump to previous bookmark
Ctrl+K, Ctrl+N Jump to next bookmark
Ctrl+M, Ctrl+M Open/close current fold
Ctrl+M, Ctrl+O Fold all methods
Ctrl+R, Ctrl+R Enables or disables word wrap in an editor.
Ctrl+Shift+B Build solution
Ctrl+Shift+C Displays the Class View window
Ctrl+Shift+Enter Open line below line cursor is on
Ctrl+Shift+F Global Search
Ctrl+Shift+F9 Delete all breakpoints
Ctrl+Alt+A Displays the Command window, which allows you to type commands that manipulate the IDE.
Ctrl+Alt+I Displays the Immediate window, where you can evaluate expressions and execute individual commands.
Ctrl+Alt+K Displays the Task List window where you customize, categorize and manage tasks, comments, shortcuts, warnings and error messages.
Ctrl+Alt+L Open the Solution Explorer (to find your file after you just closed them all)
Ctrl+Alt+T View Document Outline
Ctrl+Alt+0 Displays the Output window to view status messages at run time
Ctrl+Alt+R Open browser within VS.NET
Ctrl+Alt+U Displays the Modules window, which allows you to view the .dll or .exe files used by the program. In multiprocess debugging, you can right-click and select Show Modules for all Programs.
Ctrl+Alt+X Open Toolbox
Shift+Alt+Enter View editor in full screen mode

Source: http://virendrablogs.blogspot.com/2009/12/visual-studio-list-of-some-shortcut.html

OpenFileDialog.SafeFileName March 10, 2009

Posted by Bilal in .NET, C#, Microsoft, VB, Visual Studio 2005, Visual Studio 2008.
Tags: , , , , , ,

I had developed an application in VS2008 with .NET 2.0 . The application was deployed using the VS2008 deployment project  with .NET Framework as pre-req. AutoCAD 2009 was already installed on all the client machines so the pre-req conditions were satisfied so .NET Framework was not skipped during the installation of the application.

Later on,  I made a clean installation of WIN XP SP3 on my development machine. I skipped VS 2008 because I could not find its proper usage. VS2005 was sufficient for me.

Today, I got the a request for some updates in the application. For this purpose, I converted it to VS2005. On building the application is got the error about OpenFileDialog.SafeFileName. It was really a strange thing as the application was working smoothly on all the client machines.

SafeFileName returns only the File Name from the whole path. Although, I got the problem solved by doing some string operations:
String safeName = opdg.FileName.Substring(opdg.FileName.LastIndexOf("\\") + 1);
// 1 has been added to skip the \

I Googled about it and it was disclosed that this property is available in .NET Framework 2.0 SP1 which is installed along with VS2008.

Missing Items in Visual Studio 2005 Menu February 22, 2009

Posted by Bilal in .NET, C#, Microsoft, SQL Server 2005, Tips & Tricks, VB, Visual Studio 2005.
Tags: , , , , , ,
1 comment so far

I noticed some missing menu items in the VS2005 (like clean, rebuild, and many others) but i continued by using the commands from other locations; until I got stucked!  I wanted to export a form as a template but the Export was not available in the File menu.
The details of my environment are:

Since, I installed Resharper for the first time, the first option that came to my mind is that its due to Resharper. I tried to explore different options in the Resharper and VS specially the Key Mapping but no result. I was only left with the option to uninstall Resharper and I did it. But to my surprise, the problem was still there.
In such a situation, I call my rescue agent GooGle. The first suggestion provided by the agent worked well and my problem was solved.
I had installed SQL Server 2005 for the first time (initially, I was using SQL 2000 as per client requirements) but I don’t considered it bcoz it’s a Microsoft product and it was least expected to interfere in the scenario. I was WRONG. This problem occurred due to a bug in it.

Here is the solution provided by Microsoft.

Hope it will also solve your problem if u faced such an issue.