Application.GetResourceStream Method (StreamResourceInfo, Uri)


Returns a resource file from a location in the specified zip package.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Public Shared Function GetResourceStream ( _
	zipPackageStreamResourceInfo As StreamResourceInfo, _
	uriResource As Uri _
) As StreamResourceInfo


Type: System.Windows.Resources.StreamResourceInfo
A StreamResourceInfo that contains the zip package stream with the desired resource file.
Type: System.Uri
A relative URI that identifies the resource file to be extracted from the zip package. The URI is relative to the application package and does not need a leading forward slash.

Return Value

Type: System.Windows.Resources.StreamResourceInfo
A StreamResourceInfo that contains the stream for the desired resource file.


The application class is not initialized.


uriResource is an absolute URI.


zipPackageStreamResourceInfo is Nothing.


uriResource is Nothing.

The GetResourceStream(StreamResourceInfo, Uri) method provides more flexibility than GetResourceStream(Uri) by allowing you to extract a resource file from an arbitrary zip package.

The following example shows how to extract an image resource file from a zip package that is located at the Silverlight application's site of origin.

Run this sample

<UserControl x:Class="SilverlightApplication.PageLong"

    <StackPanel x:Name="stackPanel" />


Imports System.Windows.Resources
Imports System.IO
Imports System.Windows.Media.Imaging

Partial Public Class PageLong
    Inherits UserControl

    Private WithEvents webClient As New WebClient

    Public Sub New()

        ' Load an image resource file that is included in a ZIP package 
        ' at the site of origin. 

        ' Specify the zip package with the image resource to get. 
        Dim uri As New Uri("", UriKind.Relative)

        ' Download the zip package. 

    End Sub

    Private Sub webClient_OpenReadCompleted(ByVal sender As Object, _
        ByVal e As OpenReadCompletedEventArgs) _
        Handles webClient.OpenReadCompleted

        ' Extract the desired image from the zip package.
        Dim zipPackageStream As Stream = e.Result
        Dim image As Image = LoadImageFromZipPackage( _
            "ImageInZipPackage.png", zipPackageStream)

    End Sub

    Public Function LoadImageFromZipPackage( _
        ByVal relativeUriString As String, _
        ByVal zipPackageStream As Stream) As Image

        ' Get the image stream at the specified URI that 
        ' is relative to the application package root. 
        Dim uri As New Uri(relativeUriString, UriKind.Relative)
        Dim zipPackageSri As New StreamResourceInfo(zipPackageStream, Nothing)
        Dim imageSri As StreamResourceInfo = _
            Application.GetResourceStream(zipPackageSri, uri)

        ' Convert the stream to an Image. 
        Dim bi As New BitmapImage()
        Dim img As New Image()
        img.Source = bi

        Return img

    End Function

End Class


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions