Search code examples
c#asp.netopenfiledialog

Browse for folder in C# VS2005


I have a file format converter on my VS2005 using C#. Now my destination path is hard coded, and I would like to make it such that the user is able to browse for a path to store the output file.

I have googled and saw that I can use OpenFileDialog control in VS2005 toolbox under Dialogs. But I am not able to find that control in my VS2005.

I do not know if it is possible to save the filepath of the uploaded file, but I am able to save the file name and extension of the file that the user browses for. E.g. Grep file name: string strFileName = Server.HtmlEncode(TextFile.FileName); Grep file extension: string strExtension = Path.GetExtension(strFileName);

I would like to ask 2 questions:

  1. Is there an alternative for OpenFileDialog which I can use to browse for folders?
  2. Is there a statement which is able to grep the filepath of the file like what I have did to grep the filename and file extension?

Thank You

Any alternatives which I can use?


Solution

  • You're looking for the FolderBrowserDialog class.

    If you're using WPF, you'll need to add a reference to System.Windows.Forms, since WPF doesn't have its own version of this class.

    If you're using ASP.Net, this is totally impossible, as is using a hard-coded path; you need to serve the file as a download.


    You're also looking for Path.GetDirectoryName.