Solved

uri format exception

Posted on 2014-01-21
7
1,113 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now