Get Application Path for ASP.NET

To get the full application path (for example to a folder named Documents) in ASP.NET do the following.

1. If you are on a webpage you can use the request object.

string DocPath = Request.MapPath(@"/Documents/");

2. If you are in a class you can use HTTPContext

string DocPath = HttpContext.Current.Request.MapPath(@"/Documents/");

Result: E:\Development\VS2010\MailMerge\MailMerge\Documents\

ASP.NET Detect Monitor Size load Style Sheet Dynamically

(If you use Bootstrap...nothing to see here)With more and monitor sizes to deal with there are times when a website will need to load different cascading style sheets.  If you have a site that has a fixed grid, for example, and you do not want it to wrap or allow the user to alter the look, you may need to load multiple style sheets.

Here is one method. In the header section of your Master Page load a different style sheet based on monitor resolution.

<script type="text/javascript">
    var screenWidth = screen.availWidth;


    if (screenWidth > 1024) {
        document.write('<link rel="stylesheet" type="text/css" href="main_highres.css"/>');

    if (screenWidth <= 1024) {
        document.write('<link rel="stylesheet" type="text/css" href="main.css"/>');

ASP.NET Add Double Click to ListBox

You have an ASP.NET ListBox and you want to be able to allow users to Double Click on the list box to select items.  You can add a hidden button to your page and then add a double click event to the list box to select items as shown below.

//Setup a string that will call a hidden button click event
string BntListBoxClick =  "document.getElementById('" 
                               + BtnAddToTarget.ClientID.ToString() + "')" 
                               + ".click();";

//Add the double click event to the list box
LBoxSelectItems.Attributes.Add("OnDblClick", BntListBoxClick);