How might I go about saving items from the listbox to a specified area on my hdd I have it showing files from a LAN, then after selecting a file, how do I save it
But after running it, selecting the item in the listbox1, and selecting copy, I get an odd error, but I do not have access to the printscreen that I took of it... I guess it does require the ToString method for listbox1.selecteditem. But how might I go about putting a proper string beside listbox1 without making it underline the whole thing as being wrong
Until I get your response, I guess I'll search for some examples.
Edit: I tried tis at school, but forgot that they do not have the .net version... so I do not know if it works or not. I tried this after searching some sites, tell me if this makes any sense.
In that case, I think you're there. You dont need the for loop. Just run the filecopy and you're done. You might have to call ToString on SelectedItem to get the actual filename.
Ok, I got the FileCopy working, I tested that, and that simply works, but now to create the variable "foo" as the selected item in the listbox is a whole different task. I get an error with the highlighted line in red, and curious what it should be changed to, and if the code in general looks correct.
Dim foo As Long For foo = 0 To ListBox1.SelectedItem
Next foo
FileCopy(Text1.Text & "foo", "C:\" & "foo") End Sub
I am trying to be able to save the contents of the selected file from the listview1. How might I go about this exactly Here is my code for retrieving the list to be displayed in the listview.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' make a reference to a directory Dim di As New IO.DirectoryInfo(Text1.Text) Dim diar1 As IO.FileInfo() = di.GetFiles() Dim dra As IO.FileInfo 'list the names of all files in the specified directory For Each dra In diar1 ListBox1.Items.Add(dra) Next End Sub
File.Open will open the file, then you read the contents and save it back out to another file, again using File.Open. Again, check the documentation to learn more about using files.
I'm not exactly sure what you are trying to accomplish here. First of all, SelectedItem returns the actual item that was initially inserted into the listbox (either manually or through databinding). I think what you want is SelectedIndex. But i'm still not sure what this code is supposed to be doing. Why are you inserting foo into the filenames
The point of the whole thing is to have text1.text = the user defined directory that has the listbox1 display all of its file contents. After that, the user may click on a file in listbox1, then click the copy command button to copy it to C:\.
I have narrowed it down to something along the lines of: FileCopy(Text1.Text & ListBox1.SelectedItem, "C:\" & ListBox1.SelectedItem)
Instead of the variable foo, and the loop. In this case, text1.text = user defined directory, and listbox1.selecteditem = the file itself selected from listbox1, (destination1). To destination 2, which is C:\, (as the directory) and having the same listbox1.selecteditem to show that the replication is copied here.
What exactly are you trying to save The list of items, which item is selected, the contents of the selected item...something else In general saving information to files is done using the System.IO.File class; check out the documentation and see if you can find what you are looking for.
Saving Files From ListBox
Galin Iliev
I get no prior errors to running the program, (i.e., no underlined blatnatly wrong text) for the following:
FileCopy(Text1.Text & ListBox1.SelectedItem, "C:\" & ListBox1.SelectedItem)
But after running it, selecting the item in the listbox1, and selecting copy, I get an odd error, but I do not have access to the printscreen that I took of it... I guess it does require the ToString method for listbox1.selecteditem. But how might I go about putting a proper string beside listbox1 without making it underline the whole thing as being wrong
Until I get your response, I guess I'll search for some examples.
Edit:
I tried tis at school, but forgot that they do not have the .net version... so I do not know if it works or not. I tried this after searching some sites, tell me if this makes any sense.
FileCopy(Text1.Text & ToString(ListBox1.SelectedItem), "C:\" & ToString(ListBox1.SelectedItem))
Galinace
sean chen
Dim foo As Long
For foo = 0 To ListBox1.SelectedItem
Next foo
FileCopy(Text1.Text & "foo", "C:\" & "foo")
End Sub
nbezalel
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' make a reference to a directory
Dim di As New IO.DirectoryInfo(Text1.Text)
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub
Startatrix
Tryst
Sudhir Kumar
I have narrowed it down to something along the lines of:
FileCopy(Text1.Text & ListBox1.SelectedItem, "C:\" & ListBox1.SelectedItem)
Instead of the variable foo, and the loop. In this case, text1.text = user defined directory, and listbox1.selecteditem = the file itself selected from listbox1, (destination1). To destination 2, which is C:\, (as the directory) and having the same listbox1.selecteditem to show that the replication is copied here.
To explain in example terms:
FileCopy(C:\New Folder\ & hello.exe, "C:\" & hello.exe)
Do you know what I mean now If you require a printscreen of the form to make it easier to grasp, just say the word.
Derek Newkirk