Move files from Listview to new directory in vb.net -


i'm trying write code in users can add files listview. these files must moved user specified location. can't work filepath of files added listview. here's code moving file:

spath = my.settings.defaultpath & combobox1.text & "\" & combobox2.text & "\"         if txtonderwerp.text = ""             if combobox3.text = "make choice..."                 msgbox("select subject!", msgboxstyle.information)             else                 try                     each item listviewitem in listview1.items                         my.computer.filesystem.copyfile(item, spath & combobox3.text & "\" & item.text, fileio.uioption.alldialogs)                         msgbox("copy succesfull.", msgboxstyle.information)                         listview1.items.clear()                         me.close()                     next                 catch ex exception                     messagebox.show("error copying file: " & ex.message)                 end try             end if         end if 

the code above states error because 'item' not string filssystem.copy command. users can add files listview code:

 using ofd new openfiledialog         ofd.multiselect = true         if ofd.showdialog = dialogresult.ok             each fn string in ofd.filenames                 dim fi new io.fileinfo(fn)                 dim icons icon = systemicons.winlogo                 dim li new listviewitem(fi.name, 1)                 if not (imagelist1.images.containskey(fi.extension))                     icons = system.drawing.icon.extractassociatedicon(fi.fullname)                     imagelist1.images.add(fi.extension, icons)                 end if                 icons = icon.extractassociatedicon(fi.fullname)                 imagelist1.images.add(icons)                 listview1.items.add(fi.name, fi.extension)             next         end if     end using 

answer advice andrew mortimer.

code listview: dim str(2) string dim itm listviewitem

    using ofd new openfiledialog         ofd.multiselect = true         if ofd.showdialog = dialogresult.ok             each fn string in ofd.filenames                 dim fi new io.fileinfo(fn)                 dim icons icon = systemicons.winlogo                 'dim li new listviewitem(fi.name, 1)                 if not (imagelist1.images.containskey(fi.extension))                     icons = system.drawing.icon.extractassociatedicon(fi.fullname)                     imagelist1.images.add(fi.extension, icons)                 end if                 str(0) = fi.name                 str(1) = fi.fullname                 icons = icon.extractassociatedicon(fi.fullname)                 imagelist1.images.add(icons)                 itm = new listviewitem(str)                 listview1.items.add(itm)             next         end if     end using 

code copying items in listview:

dim str string dim copyfilename string dim newdir string try                     newdir = my.settings.defaultpath & combobox1.text & "\" & combobox2.text & "\" & txtonderwerp.text                     my.computer.filesystem.createdirectory(newdir)                      each item listviewitem in listview1.items                         copyfilename = item.text                         str = item.subitems.item(1).text                         my.computer.filesystem.copyfile(str, newdir & "\" & copyfilename)                         msgbox("kopiƫren gelukt.", msgboxstyle.information)                         listview1.items.clear()                         me.close()                     next                 catch ex exception                     messagebox.show("error: " & ex.message)                 end try 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -