Results 1 to 7 of 7

Thread: Searching for and copying a file listed in a Datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2013
    Posts
    11

    Lightbulb Searching for and copying a file listed in a Datagridview

    I am just getting back into VB.net programming...its been a long time!

    I am writing an app that:

    1. takes two columns from an excel spreadsheet and puts them into a datagridview. One column is "filename" and the next is "quantity". I have this done so far.
    2. searches a server folder and all child folders for the file name listed in each row of the datagridview
    3. copies each file that it finds to a folder on the users desktop the amount of times in the quantity column of the datagridview

    I would really appreciate any ideas on the best way to accomplish this or code that does this or something similar. Thank you very much!

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Searching for and copying a file listed in a Datagridview

    copies each file that it finds to a folder on the users desktop the amount of times in the quantity column of the datagridview
    Huh?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2013
    Posts
    11

    Re: Searching for and copying a file listed in a Datagridview

    Quote Originally Posted by dunfiddlin View Post
    Huh?
    The users want to be able to have all of the files that are listed in the spreadsheet together in one folder on their desktop. If one row has a quantity of 2 or more the file needs to be in that folder that many times. The end result....the user doesn't have to search for and open each file individually, they can select all and open when they are ready to work on the project.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Searching for and copying a file listed in a Datagridview

    It's mostly fairly simple stuff. You would use a For Each loop to go through the rows in the grid. For each row, you can use Directory.GetFiles to get the full path of a file with a specific name under a particular folder. File.Copy will then copy the file from one folder to another. The only slightly tricky thing is copying one file to the same folder multiple times. Obviously you can't use the same destination name more than once so you would have to tack the number onto the end of the name to differentiate.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Searching for and copying a file listed in a Datagridview

    Quote Originally Posted by trollersteve View Post
    The users want to be able to have all of the files that are listed in the spreadsheet together in one folder on their desktop. If one row has a quantity of 2 or more the file needs to be in that folder that many times. The end result....the user doesn't have to search for and open each file individually, they can select all and open when they are ready to work on the project.
    And again I say, huh? How does only having one copy of each file force them to search for them individually? What's the purpose of having two identical files (in all but name as renaming is clearly necessary) open in identical applications? This looks like a bad case of the tail wagging the dog at the moment.

    Oh and now you have two (or more) copies of everything floating about how is it determined where changes should be saved?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2013
    Posts
    11

    Re: Searching for and copying a file listed in a Datagridview

    Quote Originally Posted by dunfiddlin View Post
    And again I say, huh? How does only having one copy of each file force them to search for them individually? What's the purpose of having two identical files (in all but name as renaming is clearly necessary) open in identical applications? This looks like a bad case of the tail wagging the dog at the moment.

    Oh and now you have two (or more) copies of everything floating about how is it determined where changes should be saved?

    I am only writing the requested application and not pretending to know the details of their processes. From what I understand one design department works on magazine and signage layouts. In these layouts they pick which files will be used and where they will be placed. The chosen file names are then put into a spreadsheet with how many times they are used. That spreadsheet is then delivered to the department that takes the layout and creates the end product. If there are 100 or more files in a layout the manager doesn't want the designer wasting their time searching for the files individually on the server as all of the files are not in the same folder. Each file needs to be opened and dragged into the design software. This is why they wanted all of the files that are listed in the spreadsheet copied to a folder on the desktop so that they can select all, open, and drag each file into the design software as they need it without having to search for it. After they get all of the files into the design software they will delete the folder on the desktop.

    Do you have experience with a process such as this and have a better way to suggest? I have the project just about done, but would be willing to change it up for a better process.

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Searching for and copying a file listed in a Datagridview

    You're still missing the point. You only have to find the files once. Whether they are used once, thrice or a hundred times through the layout is totally irrelevant. You don't need two copies of a file to use it twice. In fact, as both jmc and I have suggested, it would actually be counterproductive to have multiple copies since you would have to rename them meaning that the copies would no longer match with anything found in the spreadsheet and the designer would be left puzzling over what all those extra files are for. Never assume that the manager knows what he's talking about! Consult with the people that are actually going to have to use the program. If only more designers did that we'd have a lot fewer fiascos!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width