# Canceling getFileForOpening dialog

**URL:** <https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033>\
**Category:** UXP Plugin API\
**Created:** [June 4, 2021, 4:01pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033 "2021-06-04T16:01:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 4, 2021, 4:01pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/1 "2021-06-04T16:01:00Z")

</div>

Hello.

When I cancel my getFileForOpening dialog (by either hitting Cancel or escape) the execution of my plugin stops and the assigned result variable doesn’t exist at all. Any idea why that happens? Here’s the code that I use.

document.getElementById(“button\_getfile”).addEventListener(“click”, async evt =\> {  
const filename = await fs.getFileForOpening();  
if(!filename) {console.log(“Cancel”);}  
});

The console won’t show anything at all.

---

<div class="post-metadata">

**Author:** ![DavidXD](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/davidxd/32/909_2.png) [@DavidXD](https://forums.creativeclouddeveloper.com/u/DavidXD)\
**Post date:** [June 4, 2021, 5:28pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/2 "2021-06-04T17:28:27Z")

</div>

Your code is correct. I tried it and did not have a problem with cancelling the dialog.

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 4, 2021, 6:21pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/3 "2021-06-04T18:21:29Z")

</div>

I can cancel the dialog, but the “if”-condition doesn’t get triggered. I’ll try again tomorrow.

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 5, 2021, 11:32am UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/4 "2021-06-05T11:32:43Z")

</div>

> [@AndreasResch](#):
>
> const filename = await fs.getFileForOpening();  
> if(!filename) {console.log(“Cancel”);}

I’ve tried the code again and it doesn’t trigger the console output. When I put the getFileForOpening call into a “try” block, the error condition as well as the “Cancel” output are triggered. So it seems as if canceling the Open File dialog triggers an error.

document.getElementById(“button\_getfile”).addEventListener(“click”, async evt =\> {  
try{  
var filename = await fs.getFileForOpening();  
} catch {console.log(“Error”);}  
if(!filename) {console.log(“Cancel”);}  
});

And “const filename …” doesn’t work for the “if” condition afterwards, the “var filename …” version does.

Also … “sp-button” and “sp-action-button” don’t seem to work properly with the dialog either. When I trigger them, after canceling the dialog, another dialog pops up (but can’t be accessed - it’s just open in the background). A normal HTML button seems to work.

---

<div class="post-metadata">

**Author:** ![DavidXD](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/davidxd/32/909_2.png) [@DavidXD](https://forums.creativeclouddeveloper.com/u/DavidXD)\
**Post date:** [June 7, 2021, 7:22pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/5 "2021-06-07T19:22:51Z")

</div>

I am not able to reproduce any problem using this code or with other plugins. It is difficult to say what might be wrong. Can you see if you still experience the problem when using this sample plugin?

> **[AdobeXD/plugin-samples](https://github.com/AdobeXD/plugin-samples/tree/master/ui-panel-simple-drag-and-drop)**
>
> master/ui-panel-simple-drag-and-drop

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 8, 2021, 8:40am UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/6 "2021-06-08T08:40:59Z")

</div>

I’m using Photoshop, so I don’t thing that I can use this plugin. At least I can’t load it in UXP Developer.

---

<div class="post-metadata">

**Author:** ![DavidXD](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/davidxd/32/909_2.png) [@DavidXD](https://forums.creativeclouddeveloper.com/u/DavidXD)\
**Post date:** [June 8, 2021, 4:19pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/7 "2021-06-08T16:19:07Z")

</div>

The Photoshop forum might be able to help:

> **[Photoshop](https://forums.creativeclouddeveloper.com/c/photoshop/63)**
>
> This is the parent category for Photoshop. There are sub-categories for each API:

---

<div class="post-metadata">

**Author:** ![AndreasResch](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/andreasresch/32/1423_2.png) [@AndreasResch](https://forums.creativeclouddeveloper.com/u/AndreasResch)\
**Post date:** [June 8, 2021, 5:15pm UTC](https://forums.creativeclouddeveloper.com/t/canceling-getfileforopening-dialog/3033/8 "2021-06-08T17:15:17Z")

</div>

Yeah - I found that out in the meanwhile. Cheers.
