Solved

Path.GetDirectoryName

Posted on 2006-07-23
10
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

623 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