Share via


how to to get a path of a file in c#...

Question

Monday, August 15, 2011 9:31 AM

file path how can i get ???in c# i m working on file handling..vipin

All replies (3)

Monday, August 15, 2011 12:47 PM ✅Answered | 1 vote

file path how can i get ???in c# i m working on file handling.. vipin

Use System.io.path

http://msdn.microsoft.com/en-us/library/system.io.path.aspx

Complete code is given at the bottom of the page above.

Console.WriteLine("The full path of {0} is {1}.", path4, Path.GetFullPath(path4));

Please mark those posts as answer which answers your question. Faraz


Wednesday, August 17, 2011 7:45 AM ✅Answered

Hi Vipin,

Use System.IO.FileInfo for retirieving file path, directory name etc,

Here is the example

FileInfo

 

fileInfo= new FileInfo(fileName);

fileInfo.DirectoryName; //This will give the folder path which is having the file

Hope this would help.

 

Regards,

Babu.K


Monday, August 15, 2011 10:16 AM

Hi vipin,

I have here a simple code for file handling that loads the data of a textfile from the specified location to listbox using filetream.

private void ReadData()
    {
      FileStream fs = new FileStream(@"C:\Client\file2.txt", FileMode.Open, FileAccess.Read);
      StreamReader strm = new StreamReader(fs);
      strm.BaseStream.Seek(0, SeekOrigin.Begin);
      string str = strm.ReadLine();
      while (str != null)
      {
        listBox1.Items.Add(str);
        str = strm.ReadLine();
      }
      strm.Close();
      fs.Close();
    }

Hope it helps.

Thanks