views:

34

answers:

2

Hi, I need to set image source dynamically, please note my image is in somewhere on the Network, here is my code

   BitmapImage logo = new BitmapImage();
   logo.BeginInit();
   logo.UriSource = new Uri(@"pack://application:,,,\\myserver\\folder1\\Customer Data\\sample.png");
   logo.EndInit(); // Getting exception here
   ImageViewer1.Source = logo;

Exception: The URI prefix is not recognized

+1  A: 

The pack syntax you are using here is for an image that is contained as a Resource within your application, not for a loose file in the file system.

You simply want to pass the actual path to the UriSource:

logo.UriSource = new Uri(@"\\myserver\folder1\Customer Data\sample.png");
Wonko the Sane
+2  A: 

You just need one line:

ImageViewer1.Source = new BitmapImage(new Uri(@"\\myserver\\folder1\\Customer Data\\sample.png"));
Tim Robbin
You don't need to escape the backslashes if you use a verbatim string
Thomas Levesque
Thanks..........
Muhammad Akhtar