# force file to download and not open

**URL:** <https://forum.xojo.com/t/force-file-to-download-and-not-open/47160>\
**Category:** Web\
**Created:** [January 29, 2019, 9:33am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160 "2019-01-29T09:33:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [January 29, 2019, 9:33am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/1 "2019-01-29T09:33:42Z")

</div>

HI,

I’m sure i’ve asked this before but i cant seem to find the answer.

I want the user to download a pdf, but i dont want it to open it just to download it  
is that possible. it always seems to open the pdf in the current tab .

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [January 29, 2019, 11:18am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/2 "2019-01-29T11:18:31Z")

</div>

Do you have control over the headers that the server writes? I.e., the machine where the pdf sits?

---

<div class="post-metadata">

**Author:** ![Paul\_Lefebvre](https://forum.xojo.com/user_avatar/forum.xojo.com/paul_lefebvre/32/3152_2.png) [@Paul\_Lefebvre](https://forum.xojo.com/u/Paul_Lefebvre)\
**Post date:** [January 29, 2019, 1:39pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/3 "2019-01-29T13:39:20Z")

</div>

How did you implement this? Is WebFile.ForceDownload = True for the file?

[https://documentation.xojo.com/api/web/webfile.html](https://documentation.xojo.com/api/web/webfile.html)

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [January 30, 2019, 9:02am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/4 "2019-01-30T09:02:47Z")

</div>

Sometimes whether it downloads or not depends on the whim of the browser. If you zip any file first, it will force it to download too. Not recommended for large PDFs (due to time to compress), though it can be done, as they are already compressed.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [January 30, 2019, 11:27am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/5 "2019-01-30T11:27:07Z")

</div>

ForceDownload changes download to tell browser to save it as file.  
But if browser knows file extension, it may decide otherwise and prefer to show inline.

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [January 31, 2019, 11:23pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/6 "2019-01-31T23:23:14Z")

</div>

i think David and Christian are correct - it doesn’t matter what my webapp does, the browser will decide. I even changed my settings in chrome to force pdf downloads and they display in the browser!

i am displaying a listbox of invoices and the user clicks on the ones they want and then clicks download pdf. problem is once the browser displays the pdf, its in the same tab and then the back button moves the user back to my login page.

i cant think of a way round this, they just want to click on the row ( 20 or 30 times) and download the pdf for later processing.  
on other sites than mine though, they want to display the pdfs of course.

its such a pain!

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [January 31, 2019, 11:48pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/7 "2019-01-31T23:48:24Z")

</div>

[quote=422824:@Paul Lefebvre]How did you implement this? Is WebFile.ForceDownload = True for the file?

[https://documentation.xojo.com/api/web/webfile.html[/quote]](https://documentation.xojo.com/api/web/webfile.html%5B/quote%5D)

yes, its set to download= true, chrome overrides that though. makes it very hard work for the user to download 20 pdf’s ☹

---

<div class="post-metadata">

**Author:** ![Daniel\_Taylor](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Daniel\_Taylor](https://forum.xojo.com/u/Daniel_Taylor)\
**Post date:** [February 1, 2019, 1:19am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/8 "2019-02-01T01:19:41Z")

</div>

What happens when you use a clean install of Chrome with no plugins? I ask because a quick test on my machine shows that Chrome downloads the PDF when I set WebFile.ForceDownload to True.

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [February 1, 2019, 6:51am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/9 "2019-02-01T06:51:36Z")

</div>

> [@423254:@Daniel Taylor](#):
>
> What happens when you use a clean install of Chrome with no plugins? I ask because a quick test on my machine shows that Chrome downloads the PDF when I set WebFile.ForceDownload to True.

Interesting. I will have to test. Although I suspect that Im trying to push water uphill.

Perhaps the problem is that once the user has followed the url to the pdf , the back button needs to return them to where they were. Perhaps its just a question of maintaining state. Then the user can do what they like with the browser settings for pdf.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [February 1, 2019, 7:18am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/10 "2019-02-01T07:18:11Z")

</div>

forcedownload will do three things:

mime type changed to “application/octet-stream”  
Content-Disposition set to "attachment; filename= with the filename you gave.  
Content-Description set to “File Transfer”

The browser is Kindly asked to download with the Content-Disposition as well with the mime type.  
But due to a lot of bad configured web servers, they may show something with .pdf file extensions.

---

<div class="post-metadata">

**Author:** ![Peter\_Malmkjær](https://forum.xojo.com/user_avatar/forum.xojo.com/peter_malmkj%C3%A6r/32/342_2.png) [@Peter\_Malmkjær](https://forum.xojo.com/u/Peter_Malmkj%C3%A6r)\
**Post date:** [February 1, 2019, 7:48am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/11 "2019-02-01T07:48:49Z")

</div>

Have you tried to download with a dummy name, and then rename?

Just a suggestion!

---

<div class="post-metadata">

**Author:** ![David\_Cox](https://forum.xojo.com/user_avatar/forum.xojo.com/david_cox/32/227_2.png) [@David\_Cox](https://forum.xojo.com/u/David_Cox)\
**Post date:** [February 1, 2019, 9:43am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/12 "2019-02-01T09:43:21Z")

</div>

[quote=423268:@Peter Malmkjær]Have you tried to download with a dummy name, and then rename?

Just a suggestion![/quote]  
Once the browser has downloaded the dummy file, you cannot access the file system to rename it  how are you suggesting the renaming happens?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [February 1, 2019, 9:45am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/13 "2019-02-01T09:45:19Z")

</div>

ForceDownload = true should do it.  
If not, you can zip file on server and deliver zip file and hope for auto expand.  
You can even do different behavior for different browsers.

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [February 1, 2019, 10:12am UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/14 "2019-02-01T10:12:06Z")

</div>

forcedownload is definitely true.

the user doesn’t want to unzip them, they are trying to speed up the workflow.

I’m currently on 2017r1.1 - is it possible that this might be something that has changed since then?

i turned off the chrome extension jspdf and now it opens in adobe!

i don’t have the adobe extension included so it might be the desktop app. this is getting weirder!

---

<div class="post-metadata">

**Author:** ![Peter\_Malmkjær](https://forum.xojo.com/user_avatar/forum.xojo.com/peter_malmkj%C3%A6r/32/342_2.png) [@Peter\_Malmkjær](https://forum.xojo.com/u/Peter_Malmkj%C3%A6r)\
**Post date:** [February 1, 2019, 12:15pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/15 "2019-02-01T12:15:00Z")

</div>

> [@423280:@David Cox](#):
>
> Once the browser has downloaded the dummy file, you cannot access the file system to rename it  how are you suggesting the renaming happens?

Maybe; [Monkeybread Xojo plugin - MacFileOperationMBS shared methods](https://www.monkeybreadsoftware.net/files-macfileoperationmbs-shared-method.shtml#1)

---

<div class="post-metadata">

**Author:** ![Daniel\_Taylor](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Daniel\_Taylor](https://forum.xojo.com/u/Daniel_Taylor)\
**Post date:** [February 1, 2019, 8:05pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/16 "2019-02-01T20:05:32Z")

</div>

[quote=423285:@Russ Lunn]i turned off the chrome extension jspdf and now it opens in adobe!

i don’t have the adobe extension included so it might be the desktop app. this is getting weirder![/quote]

I added PDF JS to Chrome. After doing so it ignored ForceDownload and displayed the PDF in the browser. So that’s the culprit.

As to Adobe Acrobat opening the file: browsers are commonly configured to ‘open safe files.’ I personally hate this behavior, but it’s something you have no control over from a web site. If a user wants to just click rows and download the PDFs they must disable PDF Viewer extensions and any options to process files after completion.

Edit: maybe the users would be more open to zip downloads if you had them select all the PDFs they want, then sent them as one zip file. They would only have to unzip the one file. Just a thought because zip files are the only way I can see around this.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [February 3, 2019, 1:12pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/17 "2019-02-03T13:12:31Z")

</div>

Something else to try…

After setting up the webfile, set its Mime Type to:

```auto
application/octet-stream
```

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [February 3, 2019, 6:06pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/18 "2019-02-03T18:06:33Z")

</div>

But that is what forcedownload does already!?

---

<div class="post-metadata">

**Author:** ![Daniel\_Taylor](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Daniel\_Taylor](https://forum.xojo.com/u/Daniel_Taylor)\
**Post date:** [February 3, 2019, 8:48pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/19 "2019-02-03T20:48:24Z")

</div>

> [@423602:@Christian Schmitz](#):
>
> But that is what forcedownload does already!?

I would have thought the same.

---

<div class="post-metadata">

**Author:** ![Russ\_Lunn](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/5f9b8f/32.png) [@Russ\_Lunn](https://forum.xojo.com/u/Russ_Lunn)\
**Post date:** [February 3, 2019, 9:03pm UTC](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160/20 "2019-02-03T21:03:09Z")

</div>

It seemed to work! Now instead of opening in the same tab it downloads and opens in adobe on the desktop. I think that is something in Windows 10 though. Perhaps Im wrong.

[Next page](https://forum.xojo.com/t/force-file-to-download-and-not-open/47160.md?page=2)
