Get DataGridView to accept file drop from mapped drive

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
code20runner
Posts: 20
Last visit: Thu Jul 28, 2022 11:52 am

Get DataGridView to accept file drop from mapped drive

Post by code20runner »

I have a project where I can drag and drop files and folders from a local drive to a DataGridView and everything works as expected. However, when I attempt to do the same with files from a mapped drive (UNC Path shared directory), the program locks up. How would I go about achieving this task?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra »

Have you tried to debug your code. There is no issue with dropping from a UNC. The code needs to grab the correct properties.
User avatar
code20runner
Posts: 20
Last visit: Thu Jul 28, 2022 11:52 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner »

Two issues with debugging. 1. My code machine is not attached to a network where I can test the UNC path issue. 2. New to PowerShell Studio and not sure how to get the correct properties you mention.
User avatar
code20runner
Posts: 20
Last visit: Thu Jul 28, 2022 11:52 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner »

Ok. I got a mapped drive on my code machine. I ran the debugger but when I drag and drop a file from the mapped drive onto the DataGridView in my application, the debugger doesn't report any issues, it just locks up.

Below is my code for the DragDrop:
  1. $CollectDGV_DragDrop = [System.Windows.Forms.DragEventHandler]{
  2.    
  3.     foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) # $_ = [System.Windows.Forms.DragEventArgs]
  4.     {
  5.         $eachFile = Get-ChildItem $filename -Recurse
  6.        
  7.         foreach ($truefile in $eachFile | Where-Object { !$_.psiscontainer })
  8.         {
  9.             $size = [math]::Round($truefile.Length / 1MB, 1)
  10.             $CollectDGV.Rows.Add($truefile.FullName, $size)
  11.         }
  12.     }
  13.     $CollectStatusBar.Text = ("List contains $($CollectDGV.Rows.Count) items")
  14. }
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra »

Did you set a breakpoint?
User avatar
code20runner
Posts: 20
Last visit: Thu Jul 28, 2022 11:52 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner »

I don't see any breakpoints showing up or anything to indicate where the problem is located.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra »

You need to start by reviewing the debugging chapter in the product manual.
User avatar
code20runner
Posts: 20
Last visit: Thu Jul 28, 2022 11:52 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner »

Thanks for the guidance. However, my main issue isn't with debugging at the moment, it is understanding how to deal with/implement UNC Paths and DataGridViews.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get DataGridView to accept file drop from mapped drive

Post by jvierra »

No idea what is meant by "implement UNC Paths and DataGridViews". A DataGridView does not know anything about UNC paths. Are you askng how to display a UNC path in a DGV?
User avatar
code20runner
Posts: 20
Last visit: Thu Jul 28, 2022 11:52 am

Re: Get DataGridView to accept file drop from mapped drive

Post by code20runner »

I figured out the issue of the application locking up when I drag and drop a file from a mapped drive to the DataGridView box. I had to ensure I was using the -LiteralPath option and not the -Path option. All seems to be working now.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked