|
-
Jan 15th, 2004, 08:37 PM
#1
Thread Starter
Addicted Member
Browse for File and get FileName [RESOLVED by MrPolite]
Hi there guys,
I am in a desperate need to get to know the code for the following situations:
I got 1 and 3 already, but I am struggling at 2 and 4.
1. browse for folder and get folder path
VB Code:
MsgBox(FolderBrowserDialog1.SelectedPath)
2. browse for folder and get folder name
VB Code:
MsgBox "Go to [url]www.vbforums.com[/url]"
3. browse for file and get file path
VB Code:
MsgBox(OpenFileDialog1.FileName)
4. browse for file and get file name
VB Code:
MsgBox "Go to [url]www.vbforums.com[/url]"
Appreciate your time,
Thank you,
McoreD
Last edited by ~*McoreD*~; Jan 15th, 2004 at 09:35 PM.
-
Jan 15th, 2004, 08:51 PM
#2
Re: browse for file and get file name
use System.IO.Path
io.Path.GetDirectoryName gets the foldername
IO.Path.GetFileNameWithoutExtension or IO.Path.GetFileName to get the file name
for example, io.path.getdirectoryname( FolderBrowserDialog1.SelectedPath)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 15th, 2004, 09:34 PM
#3
Thread Starter
Addicted Member
Thank you!
Hi MrPolite,
Thank you for the prompt reply. 
With your code I was able to get the File Name perfectly.
4. browse for file and get file name
VB Code:
txtFileName.Text = IO.Path.GetFileName(OpenFileDialog1.FileName)
For the Directory name however, I had to change GetDirectoryName to GetFileName (very strange) in order to get the Directory Name.
2. browse for folder and get folder name
VB Code:
txtRemotePath.Text = IO.Path.[b]GetFileName[/b](FolderBrowserDialog1.SelectedPath)
Thank you very much for your help.
McoreD
-
Jan 15th, 2004, 09:36 PM
#4
Re: Thank you!
Originally posted by ~*McoreD*~
VB Code:
txtRemotePath.Text = IO.Path.[b]GetFileName<b>Hi MrPolite,
Thank you for the prompt reply. <img src="images/smilies/smile.gif" border="0" alt="" title="Smilie" class="inlineimg" />
With your code I was able to get the File Name perfectly.
4. browse for file and get file name
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">VB Code:</div>
<pre class="alt2" style="margin:0px; padding:px; border:1px inset; width:650px; max-height:372px;overflow:auto"><div dir="ltr" style="text-align:left;"><div class="vb" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">txtFileName.Text = IO.Path.GetFileName(OpenFileDialog1.FileName)</div></li></ol></div></div></pre>
</div>
For the Directory name however, I had to change GetDirectoryName to GetFileName (very strange) in order to get the Directory Name.
2. browse for folder and get folder name
</b>(FolderBrowserDialog1.SelectedPath)
Thank you very much for your help.
McoreD [/B]
umm there is one big problem with all these functions and I hate that: some of them return the path ending with a "\" and some dont... I guess your path didnt end with a "\" and that's what GetDirectoryName didnt work.... I'll look into it
edit: umm nm seems like my mistake. Just one thing to be aware of though. If your path ends with a "\", GetFileName will not return the directory name, but will return an empty string. But I don't think you need to worry about this, because the FileBrowserDialog will not return a path ending with a "\", except when you choose a root path (ie if you choose drive C it will return "C:\" but if you choose the windows directory it would return something like "C:\windows")
Last edited by MrPolite; Jan 15th, 2004 at 09:43 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|