Solved

uri format exception

Posted on 2014-01-21
7
1,131 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
7 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 100 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 62

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 125 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 125 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

770 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