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 closeMenuItem = 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");
                }
            }

        }





On Jul 21, 6:28 pm, Abobker mshkan <[email protected]> wrote:
> thanx
>
> 2009/7/21, Cerebrus <[email protected]>:
>
>
>
> > What's the problem with using the OpenFileDialog ?
>
> > On Jul 21, 5:57 pm, "David Adamo Jr." <[email protected]> wrote:
> > > 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

Reply via email to