How do I set an ImageControl Source from a file name?

To set an ImageControl's Source property from a file name string, you can use a BitmapImage class as shown in the following code snippet:

In C#:

BitmapImage bmi = new BitmapImage();
bmi.BeginInit();
bmi.UriSource = new Uri(@"Images/firstrec.gif", UriKind.Relative);
bmi.EndInit();
this.TopImage.Source = bmi;

And in VB .NET:

Dim bmi As BitmapImage = New BitmapImage()
bmi.BeginInit()
bmi.UriSource = New Uri(@"Images/firstrec.gif", UriKind.Relative)
bmi.EndInit()
Me.TopImage.Source = bmi


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 08/16/11
Comment or report problem with topic