NetTalk Central

Author Topic: xml file upload  (Read 2910 times)

Gordon Holfelder

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
    • Email
xml file upload
« on: July 03, 2012, 05:29:11 PM »
Hi All-

I'm trying to use a technique that I've seen from other web apps where an Excel report is generated as an xml file and then when opened in a browser, Excel will automatically open the file as a spreadsheet.

The attached file is such an output file. When opened in windows, the file opens properly. When accessed through firefox served up through a nettalk server I get an error.

Any ideas on how to make this work? My current work around is to give the file n xls extension. I get an error, but the file will open. Perhaps setting a content type?

Regards,
Gordon

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: xml file upload
« Reply #1 on: July 03, 2012, 10:58:36 PM »
Morning Gordon,

The secret is usually in the "content-disposition" header field.
Example 40 (File Download) is a good example to try in this case.
I copied your file to the app folder, ran the app, and added your file as a record there.

This app presents a browse, which allows you to click a link, which in turn supplies the file (from outside the web folder, which is the point of the example) but more specifically shows you setting the Content-Disposition header. As in;

p_web.HeaderDetails.ContentDisposition = 'attachment; filename="'&p_web.GetValue('name')&'"'

the "attachment" part is useful because it tells the browser to open the file with "something else" rather than attempt to display it itself. As is, it uses the "default xml viewer", which on my machine is indeed Excel. However on another machine it might be something different.

Now in this case, I used your file name, which in turn meant it had the .xml extension, and so was sent through as a content-type of xml. this is why the browser loaded the default xml reader to view it. If I change the content-type to xls though, then Excel is pretty much always the default reader for that.

p_web.ReplyContentType = p_web._GetContentType('.xls')

(be careful where you call this - for example in the netwebpage procedure it has to be in an embed _after_ the call to do Header because the header routine sets it based on the filename extension.)

One minor complication - although the file prompts the user to send it to Excel, (which is what you want), Excel complains a bit that it was expecting a file in xls format, not xml format. It still opens it just fine though.

Cheers
Bruce

Gordon Holfelder

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
    • Email
Re: xml file upload
« Reply #2 on: July 05, 2012, 12:21:26 PM »
Hello Bruce-

Thanks! That works great. This is a file generated by the app to simulate the SendTo functionality with a browse. What I did was add to the _SendFile method in the WebHandler procedure the following:

Code: [Select]
!! Set content disposition for generated excel files
IF LEFT(CLIP(loc:filename), 3) = '$$$' |
AND RIGHT(CLIP(loc:filename), 9) = 'excel.xml'
  SELF.HeaderDetails.ContentDisposition = 'attachment; filename="'&CLIP(loc:filename)&'"'
  PARENT._SendFile(p_FileName,p_header)
  RETURN
END