Solved

uri format exception

Posted on 2014-01-21
7
1,137 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 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jquery datatables, asp.net MVC 9 51
Finding Events logs for IIS website that restarts 2 14
Need a simple RegEx to search for two words 27 42
Easy filter aspnet 2 24
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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