Thursday, May 3, 2012

How to find application path in Console/VB.NET windows application

In ASP.NET web application we normally use Server.MapPath to get the application root folder path. But what we will write in VB.NET windows and console application???

Here is the two lines of code which will help you to get the application path in VB.NET windows and console application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
 
namespace ConsoleApplication2
{
    class TestConsole 
    {
        static void Main(string[] args)
        {
            string strLocation = System.AppDomain.CurrentDomain.BaseDirectory;
            Console.WriteLine(strLocation);
        }
    }
}

Below is the screen print of the above code with output,

Application path in Console application

No comments: