Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to get full path of current directory of process (from where process starts) and get/set the exit code of your process using “Environment Class” in C# (.net 2.0).

Author: Zunnair
Download Source Code : 861_source.zip

In this article you will learn how to get full path of current directory of process (from where process starts) and get/set the exit code of your process in C# and VB using “Environment Class”.

 

Get Directory Path Of Process:
Environment Class provides us a facility to get the full current directory path of our process. This is the path from where our process starts to run.
For this purpose you can use Current Directory Property. It returns a directory path as a string.
To demonstrate make a window application. Drag one text box and one button on the form. Press button. You will get path in text box.
Now write the following code on button click event
C#
private void btn_Directory_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = (System.Environment.CurrentDirectory);
            txt_Directory.Text = str;
        }
VB
Private Sub btn_Directory_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = (System.Environment.CurrentDirectory)
        txt_Directory.Text = str
    End Sub
This simple code gets the full directory path of your process..
Set Exit Code:
Environment class also provides us a facility to set the exit code of our process. For this purpose you can use property Exit Code. This property takes integer as exit code.
To demonstrate make a window application. Drag one text box and one button on the form. Write exit code in text box and press button your exit code will set.
Now write the following code on button click event:
 
C#
private void btn_set_Click(object sender, EventArgs e)
        {
            string str=string.Empty;
            str = txt_set.Text;
            int code = Convert.ToInt16(str);
            System.Environment.ExitCode = code;
        }
VB
Private Sub btn_set_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_set.Text
        Dim code As Integer = Convert.ToInt16(str)
        System.Environment.ExitCode = code
    End Sub
This is simple code to set exit code of your process.
Get Exit Code:
Environment class also provides us a facility to get the exit code of our process. For this purpose you can use property Exit Code. This property return integer as exit code.
To demonstrate make a window application. Drag one text box and one button on the form. Press button your will get exit code in text box.
Now write the following code on button click event:
C#
private void btn_get_Click(object sender, EventArgs e)
        {
            int code = System.Environment.ExitCode;
            string str = code.ToString();
            txt_get.Text = str;
        }      
VB
Private Sub btn_get_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim code As Integer = System.Environment.ExitCode
        Dim str As String = code.ToString()
        txt_get.Text = str
    End Sub
This is simple code to get exit code of your process.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
 
            this.Text = "Devasp.net Application";
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
 
        Me.Text = "Devasp.net Application"
 End Sub
 

This simple article tells how to get full path of current directory of process (from where process starts) and get/set the exit code of your process in C# and

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to count number of processors on current machine, and getting command line of your program process using “Environment Class” in C# (.net 2.0).

Disclaimer - Privacy
© 2002-2017 DevASP.net