Solved

uri format exception

Posted on 2014-01-21
7
1,145 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 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 63

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

730 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