URL into Folderitem - Error and How to

Hello,

I am attempting to download a text file and it appears that I need to have a Folderitem to force the download of a text file, otherwise the text file opens in the browser.

The following code was generated with referencing the Xojo Docs at: Xojo Folderitem Doc

Dim F as FolderItem F = New FolderItem("file://127.0.0.1/Downloads/EugeneDoc.txt", FolderItem.PathTypeURL) App.WF = WebFile.Open(f) App.WF.ForceDownload = True ShowURL(App.WF.URL)

The WF variable in a WebFile property in App. The above code works when using file folders, and I can’t seem to figure out how to create a folderitem with a URL.

Here is the error that occurs with the above code on a Windows 8.1 machine with a Chrome browser:

[code]Unhandled UnsupportedFormatException
Message: The path passed into new FolderItem was invalid

Stack:
FolderItem.Constructor%%osi4
WebPage1.WebPage1.Button1_Action%%o<WebPage1.WebPage1>o
Delegate.IM_Invoke%%o
AddHandler.Stub.28%%
WebButton._ExecuteEvent%b%osA1v
WebControl.!_ExecuteEvent%b%ssA1v
WebSession._HandleEvent%%oso<HTTPServer.HTTPRequestContext>
WebSession._HandleRequest%i4%oso<HTTPServer.HTTPRequestContext>
WebApplication.HandleHTTPRequest%%oo<HTTPServer.HTTPRequestContext>
HTTPServer.HTTPRequestThread.Event_Run%%o<HTTPServer.HTTPRequestThread>[/code]

How do I create a folderitem from a URL?

Thank you

The URL you are trying to use does not exist.

Here is what I obtain when I go :

dim f as folderitem = SpecialFolder.UserHome.child("Downloads").child("uspto.zip") if f.exists then msgbox f.URLPath

file://localhost/Users/Mitch/Downloads/uspto.zip

But why do you want to use an URL to locate a file which is on your local file system ? Use the usual folderItem notation. Then let WebFile make it a URL for download …

Look at the Downloading project in /Xojo 2014 Release 2.1/Example Projects/Web/Downloading

Hi Michel,

Greatly appreciate the comment - thank you.

Yes, manually putting in a file folder system works and I was wanting to download the file (text, exe, app, etc.) with a URL. There are a few reasons for my request of using a URL:

  1. Able to be used on many operating systems - The ‘Big 3’ internet operating systems (Linux, Windows, OS X) have different locations for each webpage structure. Using a URL would make the Xojo program less-prone to breaking when using one directory system on Windows, another system on OS X, and yet another on Linux. The URL would remain the same, and the file system would be different.
  2. The URL can be accessible with the Xojo web program to make it easier to allow updates to existing desktop programs. Security measures can be added to help prevent unwanted downloading, and this is another matter :slight_smile:

I am sure that there are many more reasons, and these are examples which I am immediately working with.

This example also works with files and not URL’s-to-files. Its a nice example and not quite what I am needing. :slight_smile:

Thanks for your answer, and if folderitems can only be created with folders (chuckle, the name gives it away), then I am good with this answer.

Using specialfolder and the folderitem structure gives you access to the whole file systems transparently as well. I do that all the time between Mac and Windows.

My point was not to discourage you to use URLPath, by the way. Just to point yours was not quite right :wink: