?
Solved

uri format exception

Posted on 2014-01-21
7
Medium Priority
?
1,195 Views
Last Modified: 2014-01-21
I am trying to copy an image at runtime into an image control.

This is my code:

void cmdHole1_Tap(object sender,
                     System.Windows.Input.GestureEventArgs e)
            // Place blank image into imgHole1
            {
                string strImageSource = "Images/" + "bbFull1.png";  // fails here.
                BitmapImage bmi = new BitmapImage();
           
                bmi.UriSource = new Uri(strImageSource, UriKind.Absolute);
                imgHole1.Source = bmi;
                txtHole1.Text = "Blank";
            }

bbFull1.png is an image contained in the Project Images folder.

What is the proper syntax?

Thanks
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 400 total points
ID: 39797662
Try adding a / in front of the Images like:
string strImageSource = "/Images/" + "bbFull1.png";

Open in new window

And try setting the UriKind to: UriKind.RelativeOrAbsolute
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39797701
Hi Dovberman;

I do not see why it would fail at this line in the code.

string strImageSource = "Images/" + "bbFull1.png";  // fails here.

seeming it is a string assignment

are you sure it is not failing here?

bmi.UriSource = new Uri(strImageSource, UriKind.Absolute);

This path, "Images/bbFull1.png", is NOT an Absolute path but a Relative path. And that states that the folder Images is in the same directory as the executable of the program, is that where it is?

Please post the exact exception and inner exception of the error you are getting.
0
 

Author Comment

by:Dovberman
ID: 39797807
Yes, it fails here:

bmi.UriSource = new Uri(strImageSource, UriKind.Absolute);

An exception of type 'System.UriFormatException' occurred in System.ni.dll but was not handled in user code


The Images directory is in the Project folder;

Solution ->PhoneApp1->Images->bbFull1.png

Thanks for your observation.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 500 total points
ID: 39797871
Try changing this line :

bmi.UriSource = new Uri(strImageSource, UriKind.Absolute);

to this :

bmi.UriSource = new Uri(strImageSource, UriKind.Relative);
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39797894
As Guru_sami says above you are passing a relative path however you have specified a urikind as absolute.

try:

bmi.UriSource = new Uri(strImageSource, UriKind.Relative);
0
 

Author Comment

by:Dovberman
ID: 39797919
Relative works!

Thanks to both of you.
0
 

Author Closing Comment

by:Dovberman
ID: 39797931
Relative works!

Thanks to both of you.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question