# How to open an attachment?

**URL:** <https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523>\
**Category:** Ignition\
**Created:** [February 12, 2019, 8:14pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523 "2019-02-12T20:14:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bzimmer](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bzimmer](https://forum.inductiveautomation.com/u/bzimmer)\
**Post date:** [February 12, 2019, 8:14pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/1 "2019-02-12T20:14:47Z")

</div>

I am trying to open a pdf attachment from a button press. Is there an easy way to do this?

---

<div class="post-metadata">

**Author:** ![bmcclain](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@bmcclain](https://forum.inductiveautomation.com/u/bmcclain)\
**Post date:** [February 12, 2019, 8:22pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/2 "2019-02-12T20:22:59Z")

</div>

Where is the PDF file located?

You can open a PDF file from the client’s PC by using the following code:

```auto
filePath = system.file.openFile("pdf")
fileData = system.file.readFileAsBytes(filePath)

```

---

<div class="post-metadata">

**Author:** ![bzimmer](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bzimmer](https://forum.inductiveautomation.com/u/bzimmer)\
**Post date:** [February 12, 2019, 8:25pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/3 "2019-02-12T20:25:10Z")

</div>

I was planning to put the files on a share drive for multiple users to be able to access. This way the PDF can be updated by someone with no programming experience. I could even put the PDF files on the gateway computer if that makes things easier.

---

<div class="post-metadata">

**Author:** ![bmcclain](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@bmcclain](https://forum.inductiveautomation.com/u/bmcclain)\
**Post date:** [February 12, 2019, 8:41pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/4 "2019-02-12T20:41:56Z")

</div>

Yeah, the easiest way would be to put the files on the Ignition server and run that code from a gateway scoped function. You could then bypass the part about doing the openFile since you already know the path to the PDF file.

From there you can then use the PDF viewer component in the designer to visually show the PDF.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 12, 2019, 8:49pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/5 "2019-02-12T20:49:57Z")

</div>

There’s some hoops to jump through when mapping a network drive that can be accessed in gateway scope: [https://docs.inductiveautomation.com/display/DOC79/Mapping+a+Network+Drive](https://docs.inductiveautomation.com/display/DOC79/Mapping+a+Network+Drive)

---

<div class="post-metadata">

**Author:** ![bzimmer](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bzimmer](https://forum.inductiveautomation.com/u/bzimmer)\
**Post date:** [February 12, 2019, 9:51pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/6 "2019-02-12T21:51:42Z")

</div>

So I have it working with the PDF Viewer tool. I have a single window that opens and the file path is bound to a parameter that is passed with the button pressed. When I press the button I get a message that says

“ICEpdf could not open the specified file at filepath.  
The file may be corrupt or not a supported file type.”

I press OK and then the file is opened in the PDF Viewer window anyway. How do I prevent the error message?

Thank you in advance,  
BZ

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 13, 2019, 4:55pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/7 "2019-02-13T16:55:27Z")

</div>

> [@bzimmer](#):
>
> I press OK and then the file is opened in the PDF Viewer window anyway. How do I prevent the error message?

This is a known bug that's on our backlog, but since the file is actually opened it's fairly low priority. The workaround from the bug ticket seems fairly easy to implement:

> Workaround: Remove the binding on the PDF Viewer Component's File Path property to its window's root container custom property. Instead, set the PDF Viewer's filePath property equal to the window root container property in an internalFrameActivated event handler on window2.

---

<div class="post-metadata">

**Author:** ![bzimmer](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bzimmer](https://forum.inductiveautomation.com/u/bzimmer)\
**Post date:** [February 14, 2019, 2:18am UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/8 "2019-02-14T02:18:19Z")

</div>

Ok I will try this in the morning.

Is there a way to do a similar operation of viewing a PDF but instead a with a word document or text file?

---

<div class="post-metadata">

**Author:** ![cody.abbott](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cody.abbott/32/17533_2.png) [@cody.abbott](https://forum.inductiveautomation.com/u/cody.abbott)\
**Post date:** [November 26, 2019, 4:04pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/9 "2019-11-26T16:04:12Z")

</div>

It would be nice if this was fixed. I still see it in 8.0.5.

---

<div class="post-metadata">

**Author:** ![bfeas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfeas/32/3783_2.png) [@bfeas](https://forum.inductiveautomation.com/u/bfeas)\
**Post date:** [June 2, 2021, 4:58pm UTC](https://forum.inductiveautomation.com/t/how-to-open-an-attachment/22523/10 "2021-06-02T16:58:11Z")

</div>

We get the error on 8.1.3 and it locks up the PC requiring a reboot.
