Hi. So i was just wondering if there is a way to get the filepath only when a user selects a file using an openfiledialog. E.g. Rather than C:\Test.txt it should be C:\

Really would appreciate the help

@Ahmed.C,
From what I understand, You need only the drive letter of the file. Am I right?

Well yes.. Sort of like if i was to choose a file from C:\Users\Ahmed.C\Documents\Anno 1404\Savegames it will only be like "C:\Users\Ahmed.C\Documents\Anno 1404\Savegames" and not like C:\Users\Ahmed.C\Documents\Anno 1404\Savegames\chosesnfile.ini"

The FoldeBrowserDialog ha s a SelectedPath property.

But how would I make it such that when i open a certain file from a directory, the textbox text should be C:\Users\Ahmed.C\Documents\Anno 1404\Savegames and not C:\Users\Ahmed.C\Documents\Anno 1404\Savegames\chosenfile.ini ?

@Ahmed.C,

I dont know whether there are any inbuilt options,but, I will give you the algorithm to your problem and you should code it probably. If any doubts in your code,Kindly post the code so that we can help further.

First store the path in a string

count the "\" in the string(path).

Loop with the condition to find the the "\" in the string.

so parse the string, If a "\" is encountered, Save the string in a temp variable.

Then repeat the process until count is equal to the value, count=count-1;

if count=count-1, print the temp variable data. It will be your necessary output.

Hope this helps you...

Have a happy Coding...:-D

Thank you soo much for that but after playing around with the code i managed to get it done. I really appreciate your help though!

Thanks!

A short version of the algorithm of ss125:

Dim path As String = “"C:\test\afolder\aFile"
Dim dir As String = path.SubString(0,path.LastIndexOf('\'))

@Ahmed.C,

If it is solved then please mark it as solved. :)

Whoops totally forgot about that sorry :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.