i learned about msdn today and cant seem to find 2 things I'm looking for.
how to add a folder only on the first open and how to show contents of a folder in a combobox..... does anyone know if these are on msdn or how to do this?
Printable View
Look up DirectoryInfo and FileInfo.
Everything you need is on MSDN, or close to it at least, but you have to go about finding it in a sensible way. If you know what class you're using then you should go straight to the help topic for that class and see if you can find anything useful in its member listing. Otherwise you have to search and to use any search engine effectively you have to provide relevant and only relevant key words.
In this case the ComboBox is irrelevant. You probably already know how to display strings in a ComboBox and even if you don't, that is a separate issue.
First of all, I can't event tell what you mean by this:so you don't really have much hope of MSDN understanding you if a person can't. You need to first think about what it is you want to do and then describe it clearly. In this case you want to get a list of files in a folder. I just went to MSDN and searched for folder list files. I got no useful matches. I changed that to directory list files and a link to the Directory.GetFiles method was high on the list of matches. I changed it to directory list files "visual basic" and the very first match was entitled "How to: Get the Collection of Files in a Directory in Visual Basic".Quote:
how to add a folder only on the first open
Hopefully that illustrates that it is (more ofthen than not) easy to find what you're looking for if you put some thought into the key words you use to search. The more experienced you get the easier it is to choose those key words, so practice makes perfect. Note that you really should install the MSDN library locally if you can. It should be installed along with the IDE every time. Unless you are not using your own machine you are being remiss if you don't install it immediately.
i can find it but i dont understand it.......... at all any way you can simplify it for me? if you know it.
if not dont worry about it and dont bother,but if you do will the folder only be added once?
Code:Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
' Specify the directories you want to manipulate.
Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir")
Try
' Determine whether the directory exists.
If di.Exists Then
' Indicate that it already exists.
Console.WriteLine("That path exists already.")
Return
End If
' Try to create the directory.
di.Create()
Console.WriteLine("The directory was created successfully.")
' Delete the directory.
di.Delete()
Console.WriteLine("The directory was deleted successfully.")
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
dont worry about opening it.
I'm not sure why you would want to create a directory just to delete it, but this code works:
Note that it will only delete the directory if there is nothing in it. Otherwise, you will have to pass a "True" parameter to delete the folder and all files/folders within it.Code:Imports System
Imports System.IO
Public Class Test
Public Shared Sub Main()
' Specify the directories you want to manipulate.
Dim di As DirectoryInfo = New DirectoryInfo("c:\MyDir")
Try
' Determine whether the directory exists.
If di.Exists Then
' Indicate that it already exists.
Console.WriteLine("That path exists already.")
Else
' Try to create the directory.
di.Create()
Console.WriteLine("The directory was created successfully.")
' Delete the directory.
di.Delete()
Console.WriteLine("The directory was deleted successfully.")
End If
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
The IO.Directory.GetFiles method returns a String array containing the full path of each file in the folder.
The IO.DirectoryInfo.GetFiles method returns a FileInfo array containing a FileInfo object for each file in the folder.You can do whatever you like with those arrays, including bind or transfer the elements to a ComboBox.vb.net Code:
Dim folderPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments Dim filePaths As String() = IO.Directory.GetFiles(folderPath) For Each filePath As String In filePaths MessageBox.Show(IO.Path.GetFileName(filePath)) Next filePath Dim folder As New IO.DirectoryInfo(folderPath) Dim files As IO.FileInfo() = folder.GetFiles() For Each file As IO.FileInfo In files MessageBox.Show(file.Name) Next file