GetResourceStream Method (Uri)
Collapse the table of content
Expand the table of content

Application.GetResourceStream Method (Uri)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Returns a resource file from a location in the application package.

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

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


Type: System.Uri
A relative URI that identifies the resource file to be loaded. If the file has a Build Action of Content, the URI is relative to the application package and you should not use a leading forward slash. If the file has a Build Action of Resource, you can use a leading forward slash, but it is not required.

Return Value

Type: System.Windows.Resources.StreamResourceInfo
A StreamResourceInfo that contains the stream for the desired resource file or Nothing if the specified resource cannot be found.


The application class is not initialized.


uriResource is an absolute URI.


uriResource is Nothing.

The GetResourceStream method enables you to load resource files with Content or Resource set as the Build Action property value. The following table lists the file types you can load with GetResourceStream:

File Location

Build Action

Notes and URI Example

Embedded in the application assembly in the application package


You can use a leading forward slash, but it is not required.


Included in the application package


You should not use a leading forward slash.


For performance reasons, if possible, you should set the Build Action for resources to Content, and load them accordingly.

The following code shows how to use GetResourceStream to load an image resource file from these two locations.

<!--ContentPanel - place additional content here-->
<StackPanel x:Name="stackPanel" Grid.Row="1"/>

Imports Microsoft.Phone.Controls
Imports System.IO
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media.Imaging
Imports System.Windows.Resources

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    Public Sub New()

        ' Load image resource files included in the application package 
        ' and resources that are embedded in assemblies included in the
        ' application package.

        ' Load an image resource file embedded in the application assembly.
        Dim img1 As Image = LoadImage("/PhoneApp1VB;component/EmbeddedInApplicationAssembly.png")

        ' Load an image resource file included the application package.
        Dim img2 As Image = LoadImage("IncludedInApplicationPackage.png")

    End Sub

    Public Function LoadImage(relativeUriString As String) 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 sri As StreamResourceInfo = Application.GetResourceStream(uri)

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

        Return img
    End Function
End Class

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2016 Microsoft