Server.MapPath February 15, 2010Posted by Bilal in .NET, APS, C#, Microsoft, Visual Studio 2005, Visual Studio 2008.
Tags: absolute path, asp, fiel location, mapPath, relative path, server
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)
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.
Some Visual Studio ShortCut Keys January 31, 2010Posted by Bilal in .NET, Keyboard Shortcuts, Tips & Tricks, Visual Studio 2005, Visual Studio 2008.
Tags: Keyboard, keys, Shortcuts, Visual Studio
|F3||Finds the next occurrence of the previous search text.|
|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.|
|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+C||Displays the Class View window|
|Ctrl+Shift+Enter||Open line below line cursor is on|
|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.|
|Shift+Alt+Enter||View editor in full screen mode|
OpenFileDialog.SafeFileName March 10, 2009Posted by Bilal in .NET, C#, Microsoft, VB, Visual Studio 2005, Visual Studio 2008.
Tags: 2.0, dotnet, OpenFileDialog, SafeFileName, SP1, VS2005, VS2008
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.