"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, March 22, 2011

using system.io.path.combine(_Path,_FileName)

 hi *.*,
some times we need to combine the folder path + filename ( eg: c:\Fname\asp.txt). I seen most of people using Concatenation to combine this, anyway the code will work But asp is providing us Path.Combine inbuilt and with many more features and can achieve this in less time.Using Path.Combine is a neat way of approach towards programing.

Demo:












 Code:


    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            _Concatenation();
            _PathCombine();
        }
        catch (Exception)
        {
            throw;
        }
    }

    void _Concatenation()
    {
        try
        {
            string _path = "C:\\Db";
            string _filename = "name01.db";
            string _Fullpath = _path +"\\"+ _filename;
            lblMsg01.Text = _Fullpath.ToString();
        }
        catch (Exception)
        {
           
            throw;
        }
       
    }

    void _PathCombine()
    {
        try
        {
            string _path = "C:\\Db";
        string _filename = "name01.db";
        string _fullpath = Path.Combine(_path, _filename);
        lblMsg02.Text = _fullpath.ToString();
        }
        catch (Exception)
        {
           
            throw;
        }
    }
I Hope u got it now....Stay tune.....
Have a nice day... 'N happy Coding :)

No comments: