Class

WebPicture


Description

Creates a picture that can be used by the web browser, either for display or downloading.

Methods

Name

Parameters

Returns

Shared

BootstrapIcon

iconName As String

WebPicture

Constructor

data As String, Filename As String = ""

Constructor

file As FolderItem

Constructor

files() As FolderItem

Constructor

mb As MemoryBlock, filename As String = ""

Constructor

Source As Picture, Format As String = "public.png"

Constructor

width As Integer, height As Integer, files() As FolderItem

Data

MemoryBlock

Assigns Value As MemoryBlock

Download

Boolean

Height

Integer

Identifier

String

Open

file As FolderItem, InMemory As Boolean = True

WebFile

Width

Integer

Events

Name

Parameters

Returns

Downloaded

Property descriptions


WebPicture.Cached

Cached As Boolean

Indicates whether or not the file is cached on the browser.

This property is read-only.


WebPicture.FileName

FileName As String

The name of the file.

Create a new file for downloading:

TextFile = New WebFile ' TextFile is a property of the web page
TextFile.MimeType = "text/plain"
TextFile.ForceDownload = True ' If False, the browser may try to display the file instead of download it
TextFile.FileName = "TextFile.txt"

TextFile.Data = "Hello, world!"

System.GotoURL(TextFile.URL) ' This causes the file to be downloaded

WebPicture.ForceDownload

ForceDownload As Boolean

Indicates whether the browser will always download the file instead of trying to display it (depending on the MIMEType). The default is False.

When True, the browser will always download the file rather than try to display it. For example, most web browsers will try to display simple text files and many will display PDF files inline. Set ForceDownload to True to instead ensure these types of files are downloaded instead.

If you find that FireFox users can't download files, try using WebControl.GotoURL and pass True for the InNewWindow parameter as well as having the user disable popup blockers.

Create a new file for downloading:

TextFile = New WebFile ' TextFile is a property of the web page
TextFile.MimeType = "text/plain"
TextFile.ForceDownload = True ' If False, the browser may try to display the file instead of download it
TextFile.FileName = "TextFile.txt"

TextFile.Data = "Hello, world!"

System.GotoURL(TextFile.URL) ' This causes the file to be downloaded

WebPicture.MIMEType

MIMEType As String

This is the MIME type of the content. Browsers rely on this to determine what to do with the content. Setting WebFile to True will override the MIMEType. Defaults to "application/octet-stream".

This example creates a text file to make available for download. You can put it on the Pressed event handler for a WebButton so that the file is downloaded when the user clicks the button:

TextFile = New WebFile ' TextFile is a property of the web page
TextFile.MimeType = "text/plain"
TextFile.ForceDownload = True ' If False, the browser may try to display the file instead of download it
TextFile.FileName = "TextFile.txt"

TextFile.Data = "Hello, world!"

System.GotoURL(TextFile.URL) ' This causes the file to be downloaded

WebPicture.Session

Session As WebSession

Session defaults to the current session which means it will only be accessible from that session.

Tip

Maintaining separate pictures for each session will use up more memory. To make a picture accessible to all sessions and thus be stored in memory only once, set the Session property to Nil.


WebPicture.URL

URL As String

The url to the file. Best used with System.

This property is read-only.

The Downloading example project uses WebFile.URL to download the png test file that was opened in the WebApplication event. The code for the Static Download button is:

If App.LogoFile <> Nil Then
  System.GotoURL(App.LogoFile.URL)
Else
  MessageBox("Whoops, no logo file available")
End If

WebPicture.UseCompression

UseCompression As Boolean

Determines if the web framework should compress a file before sending it to browsers that support gzip compression. The default value is True.

Method descriptions


WebPicture.BootstrapIcon

BootstrapIcon(iconName As String) As WebPicture

Returns the icon whose name matches the name passed in the color specified.

This method is shared.

You can find a complete list of icons here.


WebPicture.Constructor

Constructor(Data As String, Filename As String = "")

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a WebPicture from the passed string data using the specified fileName.


WebPicture.Constructor

Constructor(file As FolderItem)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a WebPicture from the specified file.


WebPicture.Constructor

Constructor(files() As FolderItem)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a WebPicture using the provided image files at various resolutions so that the WebPicture can draw appropriately on HiDPI screens.


WebPicture.Constructor

Constructor(mb As MemoryBlock, FileName As String = "")

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a WebPicture from mb using the supplied filename.


WebPicture.Constructor

Constructor(Source As Picture, Format As String = "public.png")

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a WebPicture from the passed Source Picture in the format specified by Format. Format is one of the Picture format class constants and defaults to PNG. By supplying a different format than the original picture format of the file, you can convert the picture to a new format.


WebPicture.Constructor

Constructor(width As Integer, height As Integer, files() As FolderItem)

Note

Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.

Creates a new WebPicture based at the size indicated using the provided image files at various resolutions so that the WebPicture can draw appropriately on HiDPI screens.


WebPicture.Data

Data As MemoryBlock

Returns the data in the file.


Data(Assigns As MemoryBlock)

Data is initially a 0-byte MemoryBlock. You should create a new MemoryBlock of the size that will be needed to store the data.

You can also just assign a String as the Data.

Create a new file for downloading:

TextFile = New WebFile ' TextFile is a property of the web page
TextFile.MimeType = "text/plain"
TextFile.ForceDownload = True ' If False, the browser may try to display the file instead of download it
TextFile.FileName = "TextFile.txt"

TextFile.Data = "Hello, world!"

System.GotoURL(TextFile.URL) ' This causes the file to be downloaded

WebPicture.Download

Download As Boolean

Asks the browser to download the file. If this method returns true, it means that the request was sent to the browser, not that it was actually downloaded.

This example creates a text file to make available for download. You can put it on the Pressed event handler for a WebButton so that the file is downloaded when the user clicks the button:

TextFile = New WebFile ' TextFile is a property of the web page
TextFile.MimeType = "text/plain"
TextFile.ForceDownload = True ' If False, the browser may try to display the file instead of download it
TextFile.FileName = "TextFile.txt"

TextFile.Data = "Hello, world!"

If TextFile.Download Then ' This causes the file to be downloaded
  ' Download requested
End If

WebPicture.Height

Height As Integer

The height of the picture.


WebPicture.Identifier

Identifier As String

An identifier that is unique to this WebFile.


WebPicture.Open

Open(file As FolderItem, InMemory As Boolean = True) As WebFile

Converts the passed FolderItem to a WebFile that can be downloaded. The entire file is loaded in memory when InMemory is True (the default). When InMemory is False, the file is referenced directly from the disk and data is accessed in 64K chunks.

This method is shared.

Loading the entire file into memory means that the largest file that can be used is limited to the amount of free memory, up to a maximum of about 3GB or so.

When the inMemory parameter is False, the file is attempted to be loaded using 64K chunks. It is still possible, depending on the OS, for the entire file to be temporarily loaded into memory. This is not permanent as this memory will be released by the OS as part of its normal housecleaning.

If you want to download an existing file on the server, you need to create a WebFile that points to it and save the reference. The best way to do this is to use a property of the WebApplication class. In the App.Opening event handler:

Var f As FolderItem = New FolderItem("MyFile.txt") ' Get the file using a FolderItem
If f <> Nil And f.Exists Then
  ' Convert the FolderItem to a WebFile
  App.MyFile = WebFile.Open(f) ' MyFile is a property on the App object
  App.MyFile.ForceDownload = True
End If

Now in a WebButton on a page, you can download this file like this:

If App.MyFile <> Nil Then
  System.GotoURL(App.MyFile.URL) ' Download the file
End If

WebPicture.Width

Width As Integer

The width of the picture.

Event descriptions


WebPicture.Downloaded

Downloaded

Fires when the current browser requests the file.

Use this event to display a message telling the user that the download is underway or perhaps to navigate them to a new page.

After the download is underway, send the user back to the main web page:

MainPage.Show

Notes

WebPicture has an Operator Convert method which will turn itself from/into a Picture. Both the following syntaxes are legal:

Var p As Picture = MyWebPicture
Var wp As WebPicture = p

Converting Picture to WebPicture gives you a PNG encoded image. For better performance avoid converting from WebPicture to Picture in your application and keep original Picture object.

Unlike WebFile, WebPicture defaults the session property to the session which it was created in.

Sample code

Convert a Picture, created at runtime to a WebPicture to display using a WebImageViewer:

Var p As New Picture(100, 100, 32)
p.Graphics.DrawingColor = Color.Blue
p.Graphics.FillRectangle(10, 10, 50, 50)

Var wp As WebPicture = p
ImageViewer1.Picture = wp

Compatibility

Web projects on all supported operating systems.

See also

WebFile parent class; WebHTMLViewer, WebFile, WebImageViewer, Picture