# Force user download file from server

**URL:** <https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Web-and-XML-Technology, Natural-on-Windows-Unix\
**Created:** [August 14, 2007, 12:03pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213 "2007-08-14T12:03:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelenHue](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@HelenHue](https://techcommunity.softwareag.com/u/HelenHue)\
**Post date:** [August 14, 2007, 12:03pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/1 "2007-08-14T12:03:52Z")

</div>

Hi all,

I like to force the user download file when the user click on the hyperlink. i find out one example “E3CONTYP” in sysweb3 which similar to what i want.  
The problem is, the download file window not pop up when the content type is “text/plain”. the file content will just show in the browser instead of force user to download.  
so how to force the user download every kind of file when he click on the hyperlink?  
thanks.

---

<div class="post-metadata">

**Author:** ![HelenHue](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@HelenHue](https://techcommunity.softwareag.com/u/HelenHue)\
**Post date:** [August 14, 2007, 12:54pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/2 "2007-08-14T12:54:43Z")

</div>

i find out that to pop out the download file window, we need to add these header (php code):  
header(“Content-Type: application/msword”);  
header(“Content-Disposition: attachment; filename=file.ext”);

but i don’t know how translate these php into natural code.  
as i know, natural can add CONTENT-TYPE. E.G.  
PERFORM W3CONTENT-TYPE ‘application/msword’  
so how about CONTENT-DISPOSITION?

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [August 14, 2007, 1:18pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/3 "2007-08-14T13:18:22Z")

</div>

:idea: All additional http headers can be set with:

```auto
PERFORM W3HTTP-HEADER 'headerName' 'headerValue'
```

:arrow: Your example may look like this:

```auto
OPTIONS TQMARK=OFF
#SOURCE := 'myFilename.ext'
COMPRESS 'attachment; filename="' #SOURCE '"' 
  INTO #VALUE LEAVING NO
PERFORM W3HTTP-HEADER 'Content-Disposition' #VALUE
```

:roll: Additionally to avoid caching, I would add:

```auto
PERFORM W3HTTP-HEADER 'Cache-Control' 'public'
PERFORM W3HTTP-HEADER 'Expires' '0'
PERFORM W3HTTP-HEADER 'Pragma' 'public'
```

😉 To determine the correct mime type for a given extension you can use:

```auto
PERFORM W3MIME-TYPE #MIME-TYPE #FILE-EXTENSION
```

:arrow: This call searches the mime-type for a given file extension inside the Natural text object MIMETYPE at library SYSWEB3 - may see the NAT-RES example at library SYSWEB3… and/or the documentation.

---

<div class="post-metadata">

**Author:** ![HelenHue](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@HelenHue](https://techcommunity.softwareag.com/u/HelenHue)\
**Post date:** [August 14, 2007, 1:45pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/4 "2007-08-14T13:45:00Z")

</div>

yeah… this is what i’m finding… i added it and it just work fine…  
thank you very much… :D:D

---

<div class="post-metadata">

**Author:** ![HelenHue](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@HelenHue](https://techcommunity.softwareag.com/u/HelenHue)\
**Post date:** [August 15, 2007, 9:12am UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/5 "2007-08-15T09:12:06Z")

</div>

Hi all,

Now, i’m facing problem that write content of the document to let the user download it. e.g. My original text file content is:  
Hello world.  
Testing here!

but the result by downloading it show “Hello world.#Testing here!#” (Note: # = square box(i assume this special character is line break))

1st method i try to write the content is read resource:  
PERFORM W3READ-RESOURCE " " #FILE-NAME #W3VALUE  
PERFORM W3TEXTLINE #W3VALUE

but the result shown no line break as the original text file. so i even try use read work file and write the content one by one line:

DEFINE WORK FILE 25 #FILE-NAME TYPE ‘UNFORMATTED’  
READ WORK FILE 25 #RECORD  
END-WORK  
EXAMINE #RECORD FOR H’0D’ GIVING NUMBER #LINE-NUMBER

FOR #I 1 TO #LINE-NUMBER  
#STARTPOS := #STARTPOS + 1  
EXAMINE #RECORD FOR H’0D’ GIVING POSITION #ENDPOS  
#LENGTH := #ENDPOS - #STARTPOS  
MOVE SUBSTR(#RECORD,#STARTPOS,#LENGTH) TO #CONTENT  
PERFORM W3TEXTLINE #CONTENT

```
EXAMINE #RECORD FOR H'0D' REPLACE FIRST ' '
EXAMINE #RECORD FOR #CONTENT DELETE FIRST 

```

END-FOR

i still cant get the original text file content which has line break. how to solve this problem?  
thanks.

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [August 15, 2007, 11:45am UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/6 "2007-08-15T11:45:55Z")

</div>

is the text file being read by another program when it arrives? That is, is the text file being viewed by an end-user or by a program? If it is the end-user, simply changing the program used to view the text file can make a difference since they interpret the cr/lf combinations differently: if you are using Notepad, try Wordpad or vice-versa.

---

<div class="post-metadata">

**Author:** ![Eric\_Schindler](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Eric\_Schindler](https://techcommunity.softwareag.com/u/Eric_Schindler)\
**Post date:** [August 15, 2007, 12:54pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/7 "2007-08-15T12:54:50Z")

</div>

It’s more simple…

If you work with W3TEXT\* - your data is may translated from the current Natural code page to the target code page your http server is running at. This is done e.g. automatically by EXX or the other available transport layers as DCOM or PAL (Spod).  
Second if EXX is used, and you may use the standard translation tables and then some special character e.g. CR and LF may be replaced with BLANK.  
This made it necessary to change the CR/LF to another specific string (used e.g. inside W3TEXTLINE), which is the reason that your can’t see your line breakes.

What you probably want is to transfer a file - even with binary data - to the Web Browser, without any changes.  
Therefore a second way of data transport has been introduced with SYSWEB3.  
Instead of using W3TEXT\* - or W3HTML\*, you have to use W3BINARY.  
If W3BINARY is used, your data will be delivered in a different way, and your data will be transfered without any changes. This makes it possible to transfer even pictures! But don’t mix up W3BINARY and W3TEXT\* or W3HTML\* because the data will not be combined and always only one of the data container is transfered.

If you would have used W3LOAD-RESOURCE instead of W3READ-RESOURCE, W3LOAD-RESOURCE would have automatically saved your data as binary, if the extension you use is specified at the MIMETYPE(SYSWEB3) text object for translation of the extension into a mime type and second entry at MIMEDATA(SYSEXT3) text object can be found, which specifies which mime type contains binary data.

As [i]Weihnachtb

---

<div class="post-metadata">

**Author:** ![HelenHue](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@HelenHue](https://techcommunity.softwareag.com/u/HelenHue)\
**Post date:** [August 15, 2007, 1:33pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/8 "2007-08-15T13:33:50Z")

</div>

yes, instead of using W3TEXTLINE, use W3BINARY:

PERFORM W3READ-RESOURCE 1X #FILE-NAME #CONTENT  
PERFORM W3BINARY #CONTENT

The file downloaded is just same as the file in the server. 😃 Thanks for all u guys help…

---

<div class="post-metadata">

**Author:** ![Angel\_Mendoza\_O1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/angel_mendoza_o1/32/191_2.png) [@Angel\_Mendoza\_O1](https://techcommunity.softwareag.com/u/Angel_Mendoza_O1)\
**Post date:** [August 11, 2008, 9:02pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/9 "2008-08-11T21:02:29Z")

</div>

I can generate a file from any route or only from resource Natural LIB

---

<div class="post-metadata">

**Author:** ![Angel\_Mendoza\_O1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/angel_mendoza_o1/32/191_2.png) [@Angel\_Mendoza\_O1](https://techcommunity.softwareag.com/u/Angel_Mendoza_O1)\
**Post date:** [August 11, 2008, 9:13pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/10 "2008-08-11T21:13:58Z")

</div>

Someone has a complete example of the case, forgive :shock:

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [August 12, 2008, 12:29pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/11 "2008-08-12T12:29:01Z")

</div>

:roll: See documentation about workfile handling:  
[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat634win/sm/definewo.htm#definewo](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat634win/sm/definewo.htm#definewo)  
[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat634win/sm/readwork.htm](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat634win/sm/readwork.htm)  
[http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat634win/sm/closewf.htm#closewf](http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat634win/sm/closewf.htm#closewf)

:arrow: Replace from the above example the line:

```auto
PERFORM W3READ-RESOURCE 1X #FILE-NAME #CONTENT
```

:idea: with:

```auto
DEFINE WORK FILE 12 'C:\Program Files\Software AG\Natural\6.3\License.txt' TYPE "UNFORMATTED"  
READ WORK FILE 12 #CONTENT 
END-WORK 
CLOSE WORK 12
```

for a fixed file (Windows) not part of a Natural resource directory.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:48pm UTC](https://techcommunity.softwareag.com/t/force-user-download-file-from-server/75213/12 "2021-04-02T14:48:39Z")

</div>


