Browsing the file system and getting the path to a file

3 views
Skip to first unread message

David Adamo Jr.

unread,
Jul 21, 2009, 8:57:49 AM7/21/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
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?

Cerebrus

unread,
Jul 21, 2009, 12:25:26 PM7/21/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
What's the problem with using the OpenFileDialog ?

Brandon Betances

unread,
Jul 21, 2009, 12:28:00 PM7/21/09
to DotNetDe...@googlegroups.com
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?

Abobker mshkan

unread,
Jul 21, 2009, 12:28:36 PM7/21/09
to DotNetDe...@googlegroups.com
thanx

 
2009/7/21, Cerebrus <zor...@sify.com>:



--
Baker

Ace

unread,
Jul 22, 2009, 2:13:10 AM7/22/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
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 <abobkerfa...@gmail.com> wrote:
> thanx
>
> 2009/7/21, Cerebrus <zorg...@sify.com>:

David Adamo Jr.

unread,
Jul 22, 2009, 2:58:33 AM7/22/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting


On Jul 21, 5:28 pm, Abobker mshkan <abobkerfa...@gmail.com> wrote:
> thanx
>
> 2009/7/21, Cerebrus <zorg...@sify.com>:
>
>
>
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?
Reply all
Reply to author
Forward
0 new messages