1

I have a GUI with a read-only textbox that I drag files to and a function then runs with the file. This works on my machine for files in local download folders, all file extensions, outlook email attachments, etc. I have no issues.

A colleague has begun using it and he is unable to successfully drag email attachments from outlook into the box. The arg is empty. It all works on my machine, but not his. I had one other person test, and they had the same issue.

$filebox.Add_DragEnter({
    if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) {
        $_.Effect = [Windows.Forms.DragDropEffects]::Copy
    }
})
$filebox.Add_DragDrop({
    foreach ($file in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) {
        create_dir $file # Function doesn't even trigger here with outlook email attachments because no arg
    }
})

We are all pulling from a shared inbox. Nothing is hard-coded to identify the user, or define a set path, it should just grab the path of the arg dropped in the box, right? I'm just confused how the drag/drop is working for some files but not email attachments, and then also working fully on my machine.

I would consider myself a pretty novice coder, and first time ever messing with Powershell. (I do not have access to anything else in this situation. No ability to compile c#, powershell is it.). Maybe I'm missing something fundemental here. Anyone have any thoughts on this?

thortney
  • 13
  • 2

2 Answers2

0

File format wont be present since there is no physical file on the file system. see Upload fails when user drags and drops attachment from email client

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • On my machine, if I output the $file arg instead of running the create_dir function, I get a file path in appData/local/temp folder, and the create_dir function will run. The function creates a directory based on the name of the file, and copies the file there. Thanks for the link. That makes sense to me. I just don't understand why it works on mine and not his. It does seem the file is on the filesystem for me, as the leaf of the path is the actual text file. – thortney Jun 09 '20 at 20:40
  • Example: I just outputted the arg path and i get C:\Users\{user}\AppData\Local\Temp\1\ed709666-5bdb-4b96-ac5f-c4-e6f2d384d0\G000B95X_20200609.txt -- with that txt file being the file I'm after. Now when I have my colleague do the same, the output is just empty. Is the actual bug that it is somehow working for me lol – thortney Jun 09 '20 at 20:49
  • There are addins (I wrote one if them) that intercept drag/drop start and provide an actual file in the temp folder for the outside consumption. Which addins are installed on your machine? – Dmitry Streblechenko Jun 09 '20 at 23:21
  • I got it to work. Your link sent me down the right path for sure. I pulled my add-ins just out of curiosity and thought they all looked like standard add-ins. As for the fix: I have the drop event check if filedrop, and if not, we assume its an outlook attachment (not sure how else to define and check specifically for an outlook attachment) and save the file to downloads folder, THEN move forward using the newly created download path. Cheers, thanks – thortney Jun 10 '20 at 12:21
0
$filebox.Add_DragDrop({
    if ($_.Data.GetDataPresent([System.Windows.Forms.DataFormats]::FileDrop)) {
        foreach ($file in $_.Data.GetData([System.Windows.Forms.DataFormats]::FileDrop)) {
            create_dir $file
        }
    }
    else {
        $outlook = New-Object -ComObject Outlook.Application
        $s = $outlook.ActiveExplorer().Selection
        foreach ($item in $s){
            foreach($a in $item.Attachments){
                $name = Join-Path -Path $dlpath -ChildPath $a.filename
                $a.SaveAsFile($name)
                create_dir $name
            }
        }
    }
})

As Dmitry noted, the files aren't actually saved on the machine so I can't just Copy-Item. Here, the file is saved, and then the create_dir function is called and it can copy the item from the new download path.

thortney
  • 13
  • 2