Opening and Saving files on Web App

I have a web app that I open a file and read data from, all works great. I want to be able to save and open other files that are generated by the web app. I get various errors when trying to use existing functions like SaveAsDialog, t.writeline, etc.

Can I do what I want to do?

[quote=152921:@Larry Cluchey]I have a web app that I open a file and read data from, all works great. I want to be able to save and open other files that are generated by the web app. I get various errors when trying to use existing functions like SaveAsDialog, t.writeline, etc.

Can I do what I want to do?[/quote]

Although it is only mentioned for GetSaveFolderItem, I believe the save as dialog does not exist in Web edition. You probably need to roll you own.

Writeline should work. Maybe it generates an error because your TextOutputStream is invalid.

No, the desktop prompts for file selection do not work with web apps. It doesn’t make sense to prompt the user to save a file on the server. You can just save the files directly using a FolderItem (you specify the name) with TextOutputStream. Or you can create a file on the server and provide a link for the user to download it using a WebFile.

How do I roll my own?

You don’t. Use a WebFile and a button which does a ShowURL. The browser will present a dialog allowing the user to choose where they want to save the file.

I am using this code in the action event of a “Save Button” to create and save a file on a local computer running a web app locally:

TextFile = New WebFile
TextFile.MimeType = “text/plain”
TextFile.ForceDownLoad = True
TextFile.FileName = SaveDialog.FileName.Text
TextFile.Data = “”
For K = 0 to 7
If Design.ID(K).Text > “” Then
TextFile.Data = TextFile.Data + Str(K) +","+ HVACData(1,K) +"," + HVACData(2,K) +","+ HVACData(3,K) +","+ HVACData(4,K) +","+ HVACData(5,K) +","+ HVACData(6,K) +","+ HVACData(7,K) +","+ HVACData(8,K) +","+ HVACData(9,K) +","+ HVACData(10,K) +","+ HVACData(11,K) +","+ HVACData(12,K) +","+ HVACData(13,K) +","+ HVACData(14,K) +","+ HVACData(15,K) +","+ HVACData(16,K) +","+ HVACData(17,K) +","+ HVACData(18,K)
Else
Exit For
End If
Next
TextFile.Data = TextFile.Data + FieldData(1) +","+ FieldData(2) +","+ FieldData(3) +","+ FieldData(4) +","+ FieldData(5) +","+ FieldData(6) +","+ FieldData(7) +","+ FieldData(8) +","+ FieldData(9) +","+ FieldData(10) +","+ FieldData(11) +","+ FieldData(12) +","+ FieldData(13) +","+ FieldData(14) +","+ FieldData(15) +","+ FieldData(16)
For K = 0 to 7
If Design.ID(K).Text > “” Then
TextFile.Data = TextFile.Data + Energy.StmFld(0,K) +","+ Energy.StmFld(1,K) +","+ Energy.StmFld(2,K) +","+ Energy.StmFld(3,K) +","+ Energy.StmFld(4,K) +","+ Energy.StmFld(5,K) +","+ Energy.StmFld(6,K) +","+ Energy.MistFld(0,K) +","+ Energy.MistFld(1,K) +","+ Energy.MistFld(2,K) +","+ Energy.MistFld(3,K) +","+ Energy.MistFld(4,K) +","+ Energy.MistFld(5,K) +","+ Energy.MistFld(6,K)
Else
Exit For
End If
Next
Dim CracUnit as String
If Options.RadioGroup1.CellSelected(0,0) = True Then
CracUnit = “Infrared”
Else
CracUnit = “Steam”
End If
TextFile.Data = TextFile.Data + Options.Rate.Text + “,” + Options.GasRate.Text + “,” + Options.StmRate.Text + “,” + Options.WaterRate.Text + “,” + Options.SewageRate.Text + “,” + Options.XducerCost.Text + “,” + Options.Life.Text + “,” + Options.Changes.Text _

  • “,” + Options.CanCost.Text + “,” + Options.FlushRate.Text + “,” + Options.StmLoses.Text + “,” + Options.GTS.Text + “,” + Options.RO1Model.Text + “,” + Options.RO2Model.Text + “,” + Options.RO1Cap.Text + “,” + Options.RO2Cap.Text _
  • “,” + Options.RO1Cost.Text + “,” + Options.RO2Cost.Text + “,” + Options.ROHP.Text + “,” + Options.ROMaint.Text + “,” + Options.DirectStm.Text + “,” + Options.MakeUp.Text + “,” + Options.Primary.Text + “,” + Options.AdjHrs.Text + “,” + Options.DropletFilters.Text + “,” + CracUnit

ShowURL(TextFile.URL)

I am getting an error from the browser(IE) when the ShowURL fires. It says it can’t find file. It shows the file name in the address field. I never get a chance to select where I want to save it.

Any ideas?

Where is TextFile defined?

I simplified your code:

[code]TextFile = New WebFile
TextFile.MimeType = “text/plain”
TextFile.ForceDownLoad = True
TextFile.FileName = “test.txt”
TextFile.Data = “This is a test”

ShowURL(TextFile.URL)[/code]

In my case TextFile is defined as a property of the WebPage. You need to do this because ShowURL is asynchronous. If you define it in that same method, it goes out of scope before the browser has a chance to request it.