tags:

views:

400

answers:

3

I have a textbox where user will enter the url of the image :

suppose the user enters the following string -> C:\Users\malcolm\Desktop\img.png

imgSilverPart is a image control AND imageUrl is a string what i am getting from a textbox.

imgSilverPart.Source = new BitmapImage(new Uri(imageUrl, UriKind.RelativeOrAbsolute));

But the image is not being displayed.

A: 

Maybe the kind of Uri was not determined corectly. Try tu use UriKind.Relative or UriKind.Absolute with valid relative or absolute url string.

PanJanek
Tried no success
Malcolm
Oh. Now I realized that the file is on your local machine and is not served via HTTP. In that case Rene's answer should guide you in a right direction.
PanJanek
+3  A: 

This won't work. Silverlight runs in a safe Sandbox and you can't just access a file on the desktop. So you have to call an OpenFileDialog, get the Stream to the file the user selected and set the Stream as source of the BitmapImage.

Add a Button in XAML and do the following in the Click event handler:

   private void Button_Click(object sender, RoutedEventArgs e)
   {
      OpenFileDialog openFileDlg = new OpenFileDialog();
      if (openFileDlg.ShowDialog().Value)
      {
         using (var stream = openFileDlg.File.OpenRead())
         {
            var bitmapImage = new BitmapImage();
            bitmapImage.SetSource(stream);
            imgSilverPart.Source = bitmapImage;
         }
      }
   }

As an alternative it's possible to use some special folders if your application runs in elevated trust mode as Out-Of-Browser app.

Rene Schulte
A: 

Hi,

Ive a Question (im really new in silverlight).

Using "saveFileDlg.SafeFileName.ToString();" i can get the name of image file test.jpeg, but how i can get the full path "c:\images\test.jpeg" OR how i can put in the source code an static path as "c:\images\".

I aprecciate very much your help, coz im developing an access control applicattion and i wish capture images of our visitors in my job.

Thanks again. Augusto M. Quito - Ecuador Southamerica

Don't post this here. Create a new question.
Javier Badia