Browsing the file system and getting the path to a file

Browsing the file system and getting the path to a file

Post by David Adamo Jr » Wed, 22 Jul 2009 21:57:49



I am looking for is a control that returns a file path, not an opened
stream or something, like OpenFileDialog does. For instance, I click a
browse button and something like the openFileDialog pops up, then I
browse to a particular file, click ok and then it provides me with the
full path to the file I selected.

Am I missing something? How do I achieve this?

 
 
 

Browsing the file system and getting the path to a file

Post by Cerebru » Thu, 23 Jul 2009 01:25:26


What's the problem with using the OpenFileDialog ?


Quote:> I am looking for is a control that returns a file path, not an opened
> stream or something, like OpenFileDialog does. For instance, I click a
> browse button and something like the openFileDialog pops up, then I
> browse to a particular file, click ok and then it provides me with the
> full path to the file I selected.

> Am I missing something? How do I achieve this?


 
 
 

Browsing the file system and getting the path to a file

Post by Brandon Betance » Thu, 23 Jul 2009 01:28:00


He just wants to display the Filename in a string or something. Something is
wrong with MSDN though so I can't find the exactly property/method to do it.
Anyone else having problems with MSDN search?


> What's the problem with using the OpenFileDialog ?


> > I am looking for is a control that returns a file path, not an opened
> > stream or something, like OpenFileDialog does. For instance, I click a
> > browse button and something like the openFileDialog pops up, then I
> > browse to a particular file, click ok and then it provides me with the
> > full path to the file I selected.

> > Am I missing something? How do I achieve this?

 
 
 

Browsing the file system and getting the path to a file

Post by Abobker mshka » Thu, 23 Jul 2009 01:28:36


thanx


> What's the problem with using the OpenFileDialog ?


> > I am looking for is a control that returns a file path, not an opened
> > stream or something, like OpenFileDialog does. For instance, I click a
> > browse button and something like the openFileDialog pops up, then I
> > browse to a particular file, click ok and then it provides me with the
> > full path to the file I selected.

> > Am I missing something? How do I achieve this?

--
Baker
 
 
 

Browsing the file system and getting the path to a file

Post by Ace » Thu, 23 Jul 2009 15:13:10


The following code browse only for the folder (not the file) in C#
Windows Application

        private void btnFolder_Click(object sender, EventArgs e)
        {
            string folderName;
            MenuItem openMenuItem = new System.Windows.Forms.MenuItem
();
            MenuItem clo*uItem = new System.Windows.Forms.MenuItem
();

            // Show the FolderBrowserDialog.
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                folderName = folderBrowserDialog1.SelectedPath;
                if (!fileOpened)
                {
                    // No file is opened, bring up openFileDialog in
selected path.
                    openFileDialog1.InitialDirectory = folderName;
                    openFileDialog1.FileName = null;
                    openMenuItem.PerformClick();

                    lblFolder.Text =
folderBrowserDialog1.SelectedPath.ToString();
                }
            }
        }

The following code Browse the FILE (inside a FOLDER) in .NET Web
application - C#

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All
files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) !=
null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.
                            lblFileName.Text =
openFileDialog1.FileName.ToString();
                            izbranEFajZaPromena = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    errorLog.SendRecordToFIle("errOnUploadFIle - " +
ex.Message.ToString() + " \n");
                }
            }

        }


> thanx


> > What's the problem with using the OpenFileDialog ?


> > > I am looking for is a control that returns a file path, not an opened
> > > stream or something, like OpenFileDialog does. For instance, I click a
> > > browse button and something like the openFileDialog pops up, then I
> > > browse to a particular file, click ok and then it provides me with the
> > > full path to the file I selected.

> > > Am I missing something? How do I achieve this?

> --
> Baker

 
 
 

Browsing the file system and getting the path to a file

Post by David Adamo Jr » Thu, 23 Jul 2009 15:58:33



> thanx


> > What's the problem with using the OpenFileDialog ?


> > > I am looking for is a control that returns a file path, not an opened
> > > stream or something, like OpenFileDialog does. For instance, I click a
> > > browse button and something like the openFileDialog pops up, then I
> > > browse to a particular file, click ok and then it provides me with the
> > > full path to the file I selected.

> > > Am I missing something? How do I achieve this?

> --
> Baker

Thanks guys. The MSDN library says the FilePath property of the
OpenFileDialog would return only the filename and I want the full path
and the filename.

Nevertheless, I tried the OpenFileDialog and I actually got the full
path to the file i.e. the FilePath property contained something like
E:/NewWorks/foo.txt and not just foo.txt as the MSDN library says it
would return. Therefore, my problem is actually solved.

Does this mean the MSDN library is a bit inaccurate or something?

 
 
 

1. Getting FIle path from remote server if i know only http file path

Hi,

I need to get List of file in a directroy which is in my WebSite
Folder.

I am trying to use Directory class so that i can get list of Files
using Directory.GetFiles() method.

But the problem is i only know the HTTP path of the folder can any one
give me a suggestion how to get that folders absolute path on the
server.

sriram

2. System Performance Engineer Position Available

3. client side browsing files not file

4. installing fonts

5. Getting the path of the file in history

6. Call Signs

7. Relative path in web.cofig file of a file that one is in app_code folder?

8. centering variable about group mean

9. How to get actual project file name and path from VSS file like"aagaaaaa.a"?

10. Config file and file paths

11. Check out project file, Path/File access error...

12. System.IO.File.Exists does not work on UNC paths??

13. Paths report on files with long paths containing spaces