Solved

Path.GetDirectoryName

Posted on 2006-07-23
10
683 Views
Last Modified: 2011-09-20
I would like to get a folder name instead of a file name and display it in the text box.
I am using this code in the ASP.NET webform but it's good only for a file name not folder name.

 Dim infolder As String
       infolder = Path.GetDirectoryName(infolder)
        txtBox.Text = infolder


Thanks
0
Comment
Question by:jskfan
  • 6
  • 4
10 Comments
 
LVL 12

Accepted Solution

by:
TheMegaLoser earned 450 total points
ID: 17164560
For Path.GetDirectoryName to recognize a folder correctly you need to end the string with a \

To get around this you can do the following:

        Dim infolder As String
        If System.IO.Directory.Exists(infolder) Then
            txtBox.Text = infolder
        Else
            txtBox.Text = System.IO.Path.GetDirectoryName(infolder)
        End If

Documentation can be found @:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiopathclassgetdirectorynametopic.asp
http://blogs.msdn.com/bclteam/archive/2004/11/16/258658.aspx
0
 

Author Comment

by:jskfan
ID: 17171210
I used the code above, but it still doesn't pick a folder when I select it on the open dialogbox, it works only for a file.
0
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 17173894
Exactly whats the string (directory) that you're trying to check?

And what do you mean with the open dialogbox in webforms? Are you talking about the file upload control or am I missing something here?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:jskfan
ID: 17177090
when you click the browse button it opens a dialog box and you can browse through drives and pickup a filename then click open and the filename with the path will showup in the textbox.
BUT what I want is instead of pickingup a filename I will be able to pickup a foldername and the foldername will showup in the textbox with the path.
0
 

Author Comment

by:jskfan
ID: 17192714
any update?
0
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 17208723
Sorry, been away for a couple of days.

I have to admit I'm a bit confused as to what you want to do. If I understand you correctly you're using the asp:fileupload control? The file upload (or INPUT TYPE=FILE as it's based on) will always upload a file. You can't change the filename of the file in the client from the server.

Even if you could the browser still wouldn't upload the entire directory you're pointing at to the server.

I'm pretty sure I've misunderstood something, can you please shed some more light? Part of the ASPX page perhaps?
0
 

Author Comment

by:jskfan
ID: 17218189
let me make it simple.

I have a textbox on ASP web page, I want a user to click the browse button and select any folder in the network and make that folder shows up on the texbox of the web page.

Because later when the user sends that web page to the administrator, the admin will give him permissions on the folder that the user selected and shown on the web page textbox.
0
 
LVL 12

Expert Comment

by:TheMegaLoser
ID: 17221648
Is the folder on the server or on the users computer?
0
 

Author Comment

by:jskfan
ID: 17227759
the folder is on the server in the network.
0
 

Author Comment

by:jskfan
ID: 17278633
any update?
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question