Minggu, 08 September 2013

How to get root directory information of the specified path in ASP.NET

Path class

Suppose you have a specified path such as "C:/my files/abc.txt" and you want to access root of the specified path (Root is "C:/"). If your path does not contain root directory information then your path class method returns null value or empty string. For accessing root information use GetPathRoot( ) method of the  Path class which is stored in System.IO namespace.

 Lets take an example 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = textBox1.Text;
            string getroot = Path.GetPathRoot(path);
            label2.Text = "Your root directory is "+getroot;


        }
    }
}

.    Output
How to get root directory information of the specified path in ASP.NETHow to get root directory information of the specified path in ASP.NET


Tidak ada komentar:

Posting Komentar