473,609 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OpenFileDialog and passing a relative directory automaticly to it


Hi

i have a circumstance where a user unzips a file, with a certain layer
of directories to get to a textfile.

So in any directory on the HDD they may end up with something like
dir1/dir2/dir3/dir4/dir5/file.txt

in most cases i can be sure the zip fie will extract as shown, but in
reality the only thing i could be certain of is the number of
directory layers and the specific names "dir5/file.txt"

so using OpenFileDialog, i want to have it auto open for the user to
the directory "dir5" so that they can click and select file.txt
without having to traverse the directories manually.

Becasue i know the numeber of directories layers will be the same, if
the directory names are not the same, how can i send releative path
information to OpenFileDialog so that it opens in correctly in dir5
for the user to select file.txt.

I must do this using relative paths, because they may extract the zip
file anyware.
any advice or help appreciated. thanks

Peter
Nov 4 '08 #1
2 4301


Sorry i should have mentioned that i can determine the directory the
zip file is in when extracted, so i need to work out how to send
relative path information from that known directory to OpenFileDialog

Peter

>Hi

i have a circumstance where a user unzips a file, with a certain layer
of directories to get to a textfile.

So in any directory on the HDD they may end up with something like
dir1/dir2/dir3/dir4/dir5/file.txt

in most cases i can be sure the zip fie will extract as shown, but in
reality the only thing i could be certain of is the number of
directory layers and the specific names "dir5/file.txt"

so using OpenFileDialog, i want to have it auto open for the user to
the directory "dir5" so that they can click and select file.txt
without having to traverse the directories manually.

Becasue i know the numeber of directories layers will be the same, if
the directory names are not the same, how can i send releative path
information to OpenFileDialog so that it opens in correctly in dir5
for the user to select file.txt.

I must do this using relative paths, because they may extract the zip
file anyware.
any advice or help appreciated. thanks

Peter
Nov 4 '08 #2
On Mon, 03 Nov 2008 23:38:29 -0800, <Petedwrote:
Hi

i have a circumstance where a user unzips a file, with a certain layer
of directories to get to a textfile.

So in any directory on the HDD they may end up with something like
dir1/dir2/dir3/dir4/dir5/file.txt

in most cases i can be sure the zip fie will extract as shown, but in
reality the only thing i could be certain of is the number of
directory layers and the specific names "dir5/file.txt"
I'm not sure I understand. Are you saying that you don't know the names
of the first four directories? Just the fifth one?
so using OpenFileDialog, i want to have it auto open for the user to
the directory "dir5" so that they can click and select file.txt
without having to traverse the directories manually.
You can set the InitialDirector y property of the OpenFileDialog before you
show it. But you _have_ to know the full path to the file you're
interested in.
Becasue i know the numeber of directories layers will be the same, if
the directory names are not the same, how can i send releative path
information to OpenFileDialog so that it opens in correctly in dir5
for the user to select file.txt.
Knowing the depth of the path in number of directories is helpful only if
you are guaranteed that at each level, there is always only one directory
to pick from. Otherwise, you have no way to know which directory to pick
at each level.

If you know the actual filename, _and_ you know that filename is unique
within the subdirectories that have been extracted, then you could do a
search of that subtree of the file system to find the file. But, if you
know the actual filename, it begs the question as to why you'd need to
present the user with the file dialog in the first place.
I must do this using relative paths, because they may extract the zip
file anyware.
I'm not sure what you mean here. Just because the files can be extracted
anywhere, that doesn't preclude using absolute paths. At some point, you
have to know _where_ the files were extracted, and at that point, you can
then construct a full absolute path representing that location.

If all you mean is that the operations to locate the file have to be
relative to some known location, then that makes sense, but that's not
really a constraint to use only relative paths. It just means that
whatever inspection of the file structure you have to do is itself
relative. The paths involved may well be absolute (and frankly, probably
should be...otherwise, you're relying on the current working directory for
your process not changing, which might be a fine assumption now but can be
easily broken in the future and is a horrible dependency to put into the
code).

Pete
Nov 4 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3074
by: don | last post by:
has anyone experienced problems with interactions between OpenFileDialog and FileStream? When I select "open" from an OpenFileDialog the subsequent calls to FileStream do not create a file. If I do anything else, eg, navigate to other folders, and then press "cancel" the file is created. This occurrs just with the simple code below. Any ideas private void button1_Click(object sender, System.EventArgs e // open the common dialog bo...
4
7989
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in Explorer i am getting error saying that cannot delete that folder as some process is using it. After that i selected a file from the same folder in OpenFileDialog. When i tried to delete the folder after selecting the file also it is giving the...
1
2328
by: Johann Blake | last post by:
A number of posts have indicated developers having problem getting an OpenFileDialog to startup in a specific directory when the dialog is shown. The first time you show the dialog, the InitialDirectory will cause the dialog to show files in that directory. However, any further times that the dialog is displayed, the directory that is shown will always be the one initially used regardless of the RestoreDirectory setting. This appears to be...
4
731
by: Chuck Edgeworth | last post by:
I'm trying to be able to select a combination of files and folders. When I try to use the OpenFileDialog it will allow me to select them but when I press the Open button it only informs me of the files I chose not the folders as well? Am I missing something? I know Microsoft can determine the folders that are selected because if you do this with the Explorer file open it will bring up windows with the contents of the folders you selected...
1
1305
by: Matthew | last post by:
The code is here: http://www.osbornewood.com/matthew/vb.cfm I am trying to Serialize soundFile.Text to an XML file. I have two buttons: Browse and Save Settings. You can enter a value the textbox and click Save Settings and it will generate a file settings.xml. The contents of soundFile.Text are in that file.
6
2998
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter property for ".dat" files at first time, it works. When I try to use openfiledialog to set different InitialDirectory an different Filter property for ".txt" files at second time, I got frozen window. Even I added code to dispose openfiledialog after...
1
3770
by: sam | last post by:
OpenFileDialog appears to be "holding onto" the parent folder of a selected file until the application using the dialog quits. After creating a folder containing a file, I attempted to select that file with an OpenFileDialog. I used the following code to create the dialog: Dim a As New OpenFileDialog a.ShowDialog() a.Dispose()
3
3247
by: Martijn Mulder | last post by:
It strikes me that System.Windows.Forms.OpenFileDialog seems te 'remember' which directory it was in last, even when a new OpenFileDialog-object is created for every access to the file system. This 'persistence' also holds between different invocations of the same program. Even when the .cs file is re-compiled, the OpenFileDialog again opens in the directory where it was directed to the previous time. 1. Is this a 'feature' of...
0
2148
by: mbewers1 | last post by:
Hi I'm having a problem trying to get a customised OpenFileDialog() to fulfil my requirements. The code for this custom-built dialog has been taken from another site (http://www.codeproject.com/KB/dialog/FileDialogExtender.aspx) ) and allows the user to select the viewing method before opening the dialog to show a file directory. The following event is assigned to a button on my form which, when prompted, displays the dialog. public...
0
8113
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8557
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8203
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8378
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5504
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4007
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2517
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.