Solved

Path.GetDirectoryName

Posted on 2006-07-23
10
674 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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 …

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now