Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have a OpenFileDialog In VB.Net

Now im able to select the multiple files and all works perfect in that side but i can workout how if a folder is selected to recurse thos files in thos directories and sub directories with It.

As i need to pass it through my code.

VB
Dim files As String() = OpenFileDialog1.FileNames
Parallel.ForEach(files, Sub(currentFile)
   'Crypto.HashSum512.HashSum.FileToCheck Is for SHA512 HashSum. Crypto.HashSum512.HashSum.FileToCheck you pass the file path to the file/files you wish to check.
   Crypto.HashSum512.HashSum.FileToCheck = currentFile
   'Crypto.HashSum512.HashSum.ComputeHash.ToString Is for returning the hash value
   Dim ValueHash = Crypto.HashSum512.HashSum.ComputeHash
   Dim safedelegate As New SafeThreadedText(AddressOf ChangeUiOutput)
   Dim SafeThreadValueHash As String = currentFile.ToString & vbTab & ValueHash & vbCrLf
   WaitEvents.Set()
   Me.Invoke(safedelegate, SafeThreadValueHash)
   End Sub)


So basically i need help with the openfiledialog when all files and folders are selected to get the files in the folders as well.

Thank you kindly for any tips hints or ideas for my issue.

additional information copied from non solution below
I need to select files or a file and any files in any folder that is selected when selecting the files.

I can't have an OpenFileDialog as well as FolderBrowseDialog on the same button and function it would be impractical and probably not very professional in design terms.

There has to be a way surely it can be done otherwise no one would use VB.Net as a programming language.

I have spent over 2 months searching and trying all sorts of things, I have spent over 6 months working on this program only to hit a wall, Everything else it complete ready to go its just this one last thing and if i can't find a solution then i will have to scrap the entire project and start from scratch with a new language, Witch could mean all that time was a waste.

I finally am asking around for help.

Thank you to anyone who can help :)
Posted
Updated 31-Dec-13 6:13am
v3
Comments
Menon Santosh 31-Dec-13 6:52am    
why don't you use folderbrowsedialog
Nelek 31-Dec-13 12:14pm    
Op told: Thanks menon, but that's not the answer I am looking for... [the rest is updated in the question]
Menon Santosh 1-Jan-14 2:11am    
openfiledialog is for file not for folder, so how can you select a folder using openfiledialog,
goto OriginalGriff's Solution

OpenFileDialog won't let you select a folder - only a file or files.
To select folders, you need the FolderBrowserDialog[^] and Directory.GetFiles[^] with the SearchOption set to AllDirectories
 
Share this answer
 
Solution 1 is perfectly valid, it seems you are stuck on the idea 'I have to use an OpenFileDialog'. In fact, you need to open all files (whether they have the same extension or not) in a given folder and its subfolders.
Let me try to translate that to VB (that's not my favorite) according to what you already have:
VB
Dim rootPath As String

Using dialog As New FolderBrowserDialog()
   If (dialog.DialogResult = DialogResult.OK)
      rootPath = dialog.SelectedPath
   End If
End Using

If Not String.IsNullOrEmpty(rootPath)
   Dim files As String() = Directory.GetFiles(rootPath, "*.*", SearchOption.AllDirectories)
   ' From here I did not touch the code...
   Parallel.ForEach(files, Sub(currentFile)
      'Crypto.HashSum512.HashSum.FileToCheck Is for SHA512 HashSum.    Crypto.HashSum512.HashSum.FileToCheck you pass the file path to the file/files you wish to check.
      Crypto.HashSum512.HashSum.FileToCheck = currentFile
      'Crypto.HashSum512.HashSum.ComputeHash.ToString Is for returning the hash value
      Dim ValueHash = Crypto.HashSum512.HashSum.ComputeHash
      Dim safedelegate As New SafeThreadedText(AddressOf ChangeUiOutput)
      Dim SafeThreadValueHash As String = currentFile.ToString & vbTab & ValueHash & vbCrLf
      WaitEvents.Set()
      Me.Invoke(safedelegate, SafeThreadValueHash)
      End Sub)
End If ' ... except here


If you have to process only a subset of all the files in the root folder, you can use another parameter than *.* in the GetFiles() call.

Keep trying; it would be such a pity to restart a project from scratch just because of such a trivial problem.
As for 'start from scratch with a new language': you don't really think it's a language problem, do you?
 
Share this answer
 
v3
Hi Menon

thank you for your reply but not the solution im looking for.

I need to select files or a file and any files in any folder that is selected when selecting the files.

I can't have an OpenFileDialog as well as FolderBrowseDialog on the same button and function it would be impractical and probably not very professional in design terms.

There has to be a way surely it can be done otherwise no one would use VB.Net as a programming language.

I have spent over 2 months searching and trying all sorts of things, I have spent over 6 months working on this program only to hit a wall, Everything else it complete ready to go its just this one last thing and if i can't find a solution then i will have to scrap the entire project and start from scratch with a new language, Witch could mean all that time was a waste.

I finally am asking around for help.

Thank you to anyone who can help :)
 
Share this answer
 
Comments
Nelek 31-Dec-13 12:12pm    
Please don't post solutions to chat with people asking or answering. The messages are not always sorted by date, so it can be a bit difficult to follow them correctly.
The best option is to use the "Have a question or comment?" (or the tiny "reply" on another comment). Another advantage is, that the person you write to will get a notification, otherwise it could be that he/she doesn't see your additional message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900