# Using CLIPBOARD to store and later paste a list of files/attachments

**URL:** <https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686>\
**Category:** questions\
**Tags:** winapi\
**Created:** [November 16, 2022, 8:55am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686 "2022-11-16T08:55:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 16, 2022, 8:55am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/1 "2022-11-16T08:55:54Z")

</div>

Good morning

Requirement: We need to find some way of using the Clarion CLIPBOARD() function to store a group of files, rather than text, and we're going to click a button to paste these files to a specified location. We know that the clipboard function can be used to store simple text and perhaps other things depending on the parameter - see below for the Clarion Help list of parameters. However, can the Clarion clipboard function be used to store and then subsequently access this list of files? If it isn't possible, we will need to look at using c# to do this. And I will probably need to look for a new job.

CF\_TEXT 1  
CF\_BITMAP 2  
CF\_METAFILEPICT 3  
CF\_SYLK 4  
CF\_DIF 5  
CF\_TIFF 6  
CF\_OEMTEXT 7  
CF\_DIB 8  
CF\_PALETTE 9  
CF\_PENDATA 10  
CF\_RIFF 11  
CF\_WAVE 12

Many thanks for your answers.

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [November 16, 2022, 9:04am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/2 "2022-11-16T09:04:49Z")

</div>

Build a list of files with some delimiter (like fileList = ‘file1.txt|file2.txt|file3.txt’) and do SETCLIPBOARD(fileList), then do fileList = CLIPBOARD() and parse the fileList. But this is a bad idea, a user may oberwrite clipboard contents between SETCLIPBOARD and CLIPBOARD calls.

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 16, 2022, 12:31pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/3 "2022-11-16T12:31:02Z")

</div>

Thanks Mike and Good Day to you,

Supposing I just want to highlight three (or any number of) random documents (.docx) or jpegs in Windows Explorer - i.e. I won’t yet have a clearly defined list that I can pre-set in the code - and then paste these chosen files somewhere within my Clarion app. Does the Clarion CLIPBOARD() function, or some other function, inherently know which files have been selected by the user in Windows and, if so, can it be interrogated to reveal & list their names? Hope that makes sense. Most documentation I can find seems to suggest that CLIPBOARD can only handle/return strings.

---

<div class="post-metadata">

**Author:** ![elankreijer](https://clarionhub.com/user_avatar/clarionhub.com/elankreijer/32/1466_2.png) [@elankreijer](https://clarionhub.com/u/elankreijer)\
**Post date:** [November 16, 2022, 12:47pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/4 "2022-11-16T12:47:59Z")

</div>

Other options are:

1. Drag & Drop, Clarion DROPID(‘~FILE’)
2. Use FileLookupButton control template or FILEDIALOGA() to let the user select files from inside the Clarion application.

That is what i normally do to let users select files.  
I am not aware of any examples to allow copy-pasting multiple file(names) from explorer into Clarion.

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 16, 2022, 1:17pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/5 "2022-11-16T13:17:55Z")

</div>

Thanks Eric,

The filedialog thing would be ok, AND DRAG&DROP might work for a single file, but here

our users are asking to be able to copy file(s) from anywhere within Explorer or Outlook

and paste them into the Clarion app, where they will be attached(added)to a database file

using a “Paste” button. It sounds like the CLIPBOARD function is pretty limited.

Gary

---

<div class="post-metadata">

**Author:** ![elankreijer](https://clarionhub.com/user_avatar/clarionhub.com/elankreijer/32/1466_2.png) [@elankreijer](https://clarionhub.com/u/elankreijer)\
**Post date:** [November 16, 2022, 1:41pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/6 "2022-11-16T13:41:26Z")

</div>

Not sure if i understand what you need, but Drag&Drop does work for multiple files. It will be a comma or semicolon separated list of filenames.  
ps. Somehow the first selected file will be the last in that list.

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 16, 2022, 1:59pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/7 "2022-11-16T13:59:55Z")

</div>

Ok, thanks. That’s interesting. If will investigate drag & drop and will write some test code to see  
whether it will do what I need.

---

<div class="post-metadata">

**Author:** ![FedericoNavarro](https://clarionhub.com/letter_avatar_proxy/v4/letter/f/2acd7d/32.png) [@FedericoNavarro](https://clarionhub.com/u/FedericoNavarro)\
**Post date:** [November 16, 2022, 3:15pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/8 "2022-11-16T15:15:53Z")

</div>

Yes, I also think that the included CLIPBOARD support doesn’t help in cases like the one mentioned or vice versa, when you need to assign the name of a file that can then be pasted with Windows Explorer.  
[Copying a file to the clipboard so you can paste it into Explorer or an email message or whatever](https://devblogs.microsoft.com/oldnewthing/20130520-00/?p=4313)

Perhaps using the APIs you can achieve it. Look at the CF\_HDROP format  
[Shell Clipboard Formats](https://learn.microsoft.com/en-us/windows/win32/shell/clipboard)  
[How to Get the File Path from Clipboard in Windows Explorer?](https://stackoverflow.com/questions/55318199/how-to-get-the-file-path-from-clipboard-in-windows-explorer)

If you want to try a simple example where you can select multiple files in Windows Explorer and drag them into a Clarion application, try this test.clw example:  
[https://clarionhub.com/t/drop-file-name-to-a-specific-row-in-the-list/5537/15](https://clarionhub.com/t/drop-file-name-to-a-specific-row-in-the-list/5537/15)

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [November 16, 2022, 3:30pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/9 "2022-11-16T15:30:01Z")

</div>

I can say, based on past experience, that supporting this stuff can be a whole lot of work, even if you’re already comfortable with these APIs. We hired a dev around 15 years ago to help us to support all of the explorer features in a SysTree and SysList. It was very involved. Worked, though.

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 16, 2022, 4:29pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/10 "2022-11-16T16:29:55Z")

</div>

Thanks all for the updates. For the moment, it does look like we’d be quicker getting our proposed “Paste” button to invoke a small c# .exe, which could then use the ready-made Microsoft functions to copy a list of selected files to the database file we use for attachments. After that I’ll be ready to retire.

---

<div class="post-metadata">

**Author:** ![dcash](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/edb3f5/32.png) [@dcash](https://clarionhub.com/u/dcash)\
**Post date:** [November 16, 2022, 10:09pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/11 "2022-11-16T22:09:49Z")

</div>

This took me all of about 5 minutes. Maybe it’s what you want?

[ClipboardTest.clw](https://clarionhub.com/uploads/short-url/ufKESkkgVrWZ9ddydAlRkFNadld.clw) (1.2 KB)

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [November 16, 2022, 11:05pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/12 "2022-11-16T23:05:13Z")

</div>

That’s a nice small code example! I’ll paste it here to allow seeing it without download.

```auto
       PROGRAM

UINT EQUATE(UNSIGNED)
LPSTR EQUATE(CSTRING)
BOOLEAN EQUATE(BYTE)           

  MAP
    Module('Windows API')
      DragQueryFileA(UINT, UINT, *LPSTR, UINT),UINT,PASCAL,RAW
      OpenClipboard(UINT),BOOLEAN,PASCAL,RAW
      CloseClipboard(),BOOLEAN,PASCAL,RAW
      GetClipboardData(UINT),UINT,PASCAL,RAW
      GetLastError(),LONG,PASCAL
    END
  END

HDROP UINT
OUTSTRING CSTRING(255)
NUMFILES UINT
RESULT UINT
SUCCESS BOOLEAN

    CODE
       
    SUCCESS = OpenClipboard(0)
    HDROP = GetClipboardData(15)
    NUMFILES = DragQueryFileA(HDROP, 0FFFFFFFFH, OUTSTRING, 255)
    Message('There are ' & NUMFILES & ' files on the clipboard')
    LOOP I# = 0 TO NUMFILES-1
        RESULT = DragQueryFileA(HDROP, I#, OUTSTRING, 255)
        IF RESULT > 0 THEN
            Message(OUTSTRING,'DragQueryFileA ' & I#)
        END
    END   
    SUCCESS = CloseClipboard()      

```

You may want to add an error message to know why it failed:

```clarion
        RESULT = DragQueryFileA(HDROP, I#, OUTSTRING, 255)
        IF RESULT > 0 THEN
            Message(OUTSTRING,'DragQueryFileA ' & I#)
        ELSE            
            Message('DragQueryFileA Error ' & GetLastError() ,'DragQueryFileA ' & I#)            
        END

```

* * *

Devuna does have this repo with OLE Drag and Drop

> **[GitHub - Devuna/Devuna-OleDragDrop: Devuna - Clarion OLE drag and drop](https://github.com/Devuna/Devuna-OleDragDrop)**
>
> Devuna - Clarion OLE drag and drop

* * *

I have this code that enumerates the different formats on the clipboard

> **[GitHub - CarlTBarnes/ClipboardEnumViewer: Clipboard Enum Formats and View](https://github.com/CarlTBarnes/ClipboardEnumViewer)**
>
> Clipboard Enum Formats and View

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 17, 2022, 7:19am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/13 "2022-11-17T07:19:41Z")

</div>

Thanks both,  
I’ll be trying those out as soon as I can make time and will report back here  
with my results.

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [November 17, 2022, 7:25am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/14 "2022-11-17T07:25:57Z")

</div>

This copy files function is in Capesoft WinEvent5  
It definatly works, because I extended the function to make it work and passed the code on to Bruce 🙂

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 17, 2022, 8:01am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/15 "2022-11-17T08:01:15Z")

</div>

I’m pleased to report that the code segment posted above works and took less than ten minutes to implement. Please accept my proposal of marriage, if indeed this is permitted in your time zone and/or state legislature. I’m sure my wife is fine with it.

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 17, 2022, 8:36am UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/16 "2022-11-17T08:36:29Z")

</div>

One minor drawback appears to be that if you open Outlook, select an email, highlight an attachment, right-click & copy, this is not picked up by the functions and the message reads as having “zero files in the clipboard”. However, this probably only needs a small tweak, is way better than what we had before.

---

<div class="post-metadata">

**Author:** ![DaveSchwReno](https://clarionhub.com/user_avatar/clarionhub.com/daveschwreno/32/1332_2.png) [@DaveSchwReno](https://clarionhub.com/u/DaveSchwReno)\
**Post date:** [November 17, 2022, 2:23pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/17 "2022-11-17T14:23:39Z")

</div>

I was considering “flag this reply” since it caused a raucous amount of laughter just behind my keyboard, thereby negating several minutes of valuable work time. 🤣

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [November 17, 2022, 2:57pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/18 "2022-11-17T14:57:38Z")

</div>

> [@garyhall69](#):
>
> open Outlook, select an email, highlight an attachment, right-click & copy, this is not picked up

You could use my enumerator to see what’s there

> **[GitHub - CarlTBarnes/ClipboardEnumViewer: Clipboard Enum Formats and View](https://github.com/CarlTBarnes/ClipboardEnumViewer)**
>
> Clipboard Enum Formats and View

---

<div class="post-metadata">

**Author:** ![garyhall69](https://clarionhub.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@garyhall69](https://clarionhub.com/u/garyhall69)\
**Post date:** [November 17, 2022, 4:24pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/19 "2022-11-17T16:24:14Z")

</div>

Thanks, it’ll probably be late next week before I return to the enhancement, but I will  
keep this in mind, definitely.

---

<div class="post-metadata">

**Author:** ![dcash](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/edb3f5/32.png) [@dcash](https://clarionhub.com/u/dcash)\
**Post date:** [November 17, 2022, 8:37pm UTC](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686/20 "2022-11-17T20:37:54Z")

</div>

> [@garyhall69](#):
>
> One minor drawback appears to be that if you open Outlook, select an email, highlight an attachment, right-click & copy, this is not picked up by the functions

Outlook uses a type of ‘virtual folders’ when copying attachments to the clipboard, so you’d have to use the CFSTR\_FILECONTENTS and CFSTR\_FILEDESCRIPTOR formats. It’s not as straight forward as getting a list of files from Explorer, so perhaps somebody else here already has a working example? If not I could probably put something together - if and when I have some spare time!

Edit: The OLE Drag & Drop example you can find in Github (posted previously by Carl) has what you need.

[Next page](https://clarionhub.com/t/using-clipboard-to-store-and-later-paste-a-list-of-files-attachments/5686.md?page=2)
