NetTalk Central

Author Topic: Giving the user choice of open or save on viewing a file on a browser  (Read 2634 times)

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
I have a button in a browse which on click displays an associated file. How do I ensure that the user has the choice of save or open. Certain file types (e.g. text and .msg) are opened directly in the browser and in the case of msg are not displayed correctly. If it's not possible to always give the choice I would rather force save and let them open afterwards.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11193
    • View Profile
set the ContentDisposition header. As in;

p_web.HeaderDetails.ContentDisposition = 'attachment; filename="whatever'''

I don't know the exact architecture of your setup, but I'm guessing the easiest way is to add a parameter to the button URL and then in WebHandler, in _SendFile, set the header if that parameter exists. If your button does something other than a URL then let me know what.

cheers
Bruce

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
If I add this code into the _SendFile procedure in the webhandler before the Parent Call my view problem is solved.
SaveFileName = st.FileNameOnly(p_FileName)
p_web.HeaderDetails.ContentDisposition = 'attachment; filename= '  & SaveFileName

SaveFileName is a local variable in the Webhandler

I need to control which procedures in the application will run this code so if I do something like

IF p_web.GSV('AllowThis')
   SaveFileName = st.FileNameOnly(p_FileName)
   p_web.HeaderDetails.ContentDisposition = 'attachment; filename= '  & SaveFileName
END

this should allow me to restrict operation of this code

How should I do this?
In the button I use to view the file I use a local variable which has the location of the file which I put into the URL field in the OnClick tab for the button. The parameter field is disabled so what would I do to set the AllowThis Sessionvalue.
I do need to do this because file upload needs to ignore this code otherwise it keeps on asking to save the uploaded file when I click save.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
can you add the parameter to the button URL?

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Hi Kevin the button URL is l:FilePath, a local variable that points to the location of the file. What would the URL be to set, say,  p_web.SSV('AllowThis','Yes')
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Giving the user choice of open or save on viewing a file on a browser
« Reply #5 on: August 01, 2014, 12:13:41 AM »
I had a look at my app and I do exactly the same as you. Technically you could add a parameter to the variable but you would need to trap that in the sendfile embed and do some processing.

You might be able to take a different approach by calling a procedure like ServeDocument and the passing your parameters including the file name.

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Giving the user choice of open or save on viewing a file on a browser
« Reply #6 on: August 01, 2014, 12:30:41 AM »
Thank Kevin.
I don't have a problem with doing some trapping in the sendfile embed, One of the beauties of StringTheory. So what should my url look like?
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Giving the user choice of open or save on viewing a file on a browser
« Reply #7 on: August 01, 2014, 04:51:08 AM »
this is just my theory...

so with your variable that is the filename, append a parameter either as part of the Variable or on the URL field in the template

eg l:var = clip(your filename) & '?myuniqueparameter=' & whatever

But really what you are doing is creating something unique about the filenames from that procedure so you can trap it and do some processing. Calling it a parameter could be confusing. maybe the following is better:

eg l:var = clip(your filename) & '^myuniqueparameter=' & whatever

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11193
    • View Profile
Re: Giving the user choice of open or save on viewing a file on a browser
« Reply #8 on: August 01, 2014, 07:29:55 AM »
I like;
eg l:var = clip(your filename) & '?myuniqueparameter=' & whatever


Terry, uou should be using
p_web.GetValue('myuniqueparameter')
not p_web.GetSessionValue
in your test.

The session value will always be true, whereas you are trying to make some decision for just this thread.


terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Giving the user choice of open or save on viewing a file on a browser
« Reply #9 on: August 01, 2014, 10:31:50 AM »
Thanks guys. I'll work on it over the weekend
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186