FolderBrowserDialog1 fails when the user selects a folder name that's to long
I was wondering if anyone know how to prevent a user to select a foldername that does have a long length name. When I run this code:
If Windows.Forms.DialogResult.OKThenIf Windows.Forms.DialogResult.OKThenIf FolderBrowserDialog1.ShowDialog() = DialogResult.OKThentxtFileDirectory.Text = FolderBrowserDialog1.SelectedPath
lblInstall.Text = txtFileDirectory.Text
btnContinue.Enabled =
TrueEndIfEndIfEndIfI get a error if I select a foldername that has a long foldername length. I think more than 50 characters.
Can anyone help?
Thank you....
B
[1550 byte] By [
Beetle54] at [2007-12-24]
Your code looks rather strange with duplicate lines.
The following code
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Me.TextBox1.Text = FolderBrowserDialog1.SelectedPath
Me.TextBox2.Text = Me.TextBox1.Text.Length
End If
Works fine with much longer paths length's than 50 - I'm up in the 120+ characters length. There is a limitation on length of a pathname but I think this is an OS limitation not a VB limitation.
So to get any assiatnce you will need to tell us what the specific error message is and on which line it is occuring.
Also which version of VB are you using ?
This issues fails when FolderBrowserDialog1.ShowDialog() is called. Once I select a folder that has a long name. I use Windwos XP Home, vb 2003.
This is the error I get when I run my program:
An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an object
what line does this happen on?
If Windows.Forms.DialogResult.OK Then
If Windows.Forms.DialogResult.OK ThenIf FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then ' this is the line that it fails on.txtFileDirectory.Text = FolderBrowserDialog1.SelectedPath
lblInstall.Text = txtFileDirectory.Text
btnContinue.Enabled =
TrueEnd IfEnd IfEnd IfHi,
' This is reading the Form DialogResult (Access of shared member)!
'If Me.FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
' This is correct
If Me.FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
MessageBox.Show(Me.FolderBrowserDialog1.SelectedPath)
End If
' No Comparison
' Is checking Integer Enum value for non zero, will always be true
If Windows.Forms.DialogResult.OK Then
MessageBox.Show("Will always be non zero or TRUE!")
End If
' Comparison
If Me.DialogResult = Windows.Forms.DialogResult.OK Then
MessageBox.Show("Form Dialogue Result is True")
End If
I cannot replicate your problem with a deep folder path.
' I suggest you use the following to get the exception text and post here
' This is probably the easiest way to it.
Try
' My folder browser stuff
' This line will throw an exception
' Dim i As Integer = CInt("NotAnInteger")
Catch ex As Exception
System.Diagnostics.Debug.WriteLine(ex.ToString)
' Place a breakpoint here
' Copy the exception info from the "Immediate Window"
Dim hold As Integer = 0
End Try
Rgds,
Martin
The code that you gave me didn't work....So I just added my code inside of this, and this is what I got
An unhandled exception of type 'System.TypeLoadException' occurred in Installer.exe
Additional information: Could not load type Microsoft.VisualBasic.Information from assembly Microsoft.VisualBasic, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a because the format is invalid.
also I got before that a Object instance is not set to a reference.
OK Getting back to the original issue. There is an OS limitation which can result in the following exception being generated
"The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."
I'm using NTFS on a windows XP system, but have tried this on Windows 2003 and Vista as well.
So this is well above your 50 characters specified. Try running the following code - which will create a structure which when navigated down to the bottom level is at 190 characters long and this works just find. If you increase the i counter to say 40 as this will inevitably cause the path name to exceed above limitation you will encounter this error when trying to create the directory. This is an OS not a VB limitation.
If the code below does not work for you - then you need to provide more details on which OS/ File system / Version of VB and the directory path you are trying to access etc. so we can try and find out why you are limited to so few characters.
Dim s As String = "C:\" For i As Integer = 1 To 12s = s & "TestDirectory" & i.ToString & "\"Nexts = s & "Test"My.Computer.FileSystem.CreateDirectory(s)If FolderBrowserDialog1.ShowDialog() = DialogResult.OK ThenMe.TextBox1.Text = FolderBrowserDialog1.SelectedPathMe.TextBox2.Text = Me.TextBox1.Text.LengthEnd If |
|
hi Spotty,
He is not creating a directoy, and I tested exactly as per your example (for) prior to my post - checking if the foldername property has a maxlength; which it appeared not to have.
Surely your scenario is too far removed from the original?
Surely you must think that there is a need to see the code, based on the exceptioin info above.
"The code that you gave me didn't work....So I just added my code inside of this, and this is what I got"
At the very least, you are confusing me. Can you please post a fuller sample of your code.
Thanks.
I am creating a folder path in code that is greater than 50 characters deep - that I know works with multiple versions of the OS and with this I can a case where this should work successfully if he navigates to the bottom node.
There is no reason he should be generating an exception with names longer than 50 characters - hence this one I know this code generates a path with 190 characters and works. If this works but his code doesnt then there may be something else at play - which is causing the exception.
There are limitations to length's but these are OS - and hence trying to generate a scenario which is a known working condition on different OS/Filesystem/Products and confirming that it still works on his specific configuration.
Agree wholeheartedly that showing his code would be useful as the error - "Object instance is not set to a reference" would probably be indicative of a missing object instantiation or user coding error.
Actually this is kind of an odd Problem...
There is no limitation on the Filesystem in regard to the length of a path... BUT there are several APIs that will supply the Path as a char(255) array, and those will go "Boom"
Hi everyone,
my code is the first messag that i left on this thread..check it out. thank you...
Brandon M. Hunter