Download BinaryStream

I’m converting some code from desktop app. It is using a library creating an excel file.

here’s the code

  dim f as folderItem
   f=SpecialFolder.Temporary.Child(filename + ".xls")
  dim bstream as BinaryStream
  bstream=BinaryStream.Create(f)
 dim writer as new ExcelWriter(bstream) 'spExcelWriter(bstream)
 writer.BeginWrite()
 writer.ProcessRecordSet(rs, lsSql, nil, True, lbWeb)
  writer.EndWrite()
  
  bstream.Close()
  
  ShowURL(f.Name)  <------------------  Compiler error: This item does not exist, Highlighting ShowURL

Anybody have an idea what I’m doing wrong.

To console?
It doesnt exist for console apps, which dont have a UI aspect

You can replace it by a shell

On Mac

Dim s as new shell s.execute("Open "+f.name)

On Windows replace “Open” by “Start”. The system may ask which browser to use the first time around.

Because you’re in a Web app you have call ShowURL from a web view (webpage). http://documentation.xojo.com/index.php/WebControl.ShowURL

Oops sorry. What I posted is for Console. Please disregard.

Bob is indeed right.

Problem is, showURL will exit the Web app and terminate the session. It would be better to use a WebHTMLViewer inside a WebPage.

There is an optional property in ShowURL that will attempt to open it in a new browser window. Sadly, there’s no way to know if the user has the Don’t Allow Popup Windows setting enabled in their browser. It then fails silently.

I’m sorry I wasn’t clear. This is a web app and the file that is created I want to download.

In the examples I saw they used it.

I modeled it after:

  If TextFile = Nil Then
    // Create a text file to download
    TextFile = New WebFile
    TextFile.MimeType = "text/plain"
    TextFile.ForceDownload = True
    TextFile.FileName = "TextFile.txt"
    
    Dim d As New Date
    d.GMTOffset = Session.GMTOffset
    
    TextFile.Data = "Hello World to " + Session.RemoteAddress + " at " + d.ShortDate + " " + d.ShortTime
    
    // The WebFile.Downloaded event handler is called when the browser
    // requests the file for downloading. This code maps that event handler
    // to the FileDownloaded method on this web page.
    AddHandler TextFile.Downloaded, AddressOf FileDownloaded
  End If
  
  // Showing the URL prompts the browser to download it
  ShowURL(TextFile.URL)

The big differance if this uses TextFile = New WebFile and the excel file is binary.

So how can the compile sat that it doesn’t exist??