tags:

views:

33

answers:

1

When I try to show an image on linklabel click, I get an error: unrecognized escape sequence.

Code:

public void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
    System.Diagnostics.Process.Start(
           "mspaint~C:\Users\Joshua Banks\Desktop\Downtown_atlanta_night.jpg");

}
+1  A: 

You need to escape the \ chararacters in your string (the image path) by either escaping them with another \ or using a verbatim string.

escape characters:

System.Diagnostics.Process.Start("mspaint~C:\\Users\\Joshua Banks\\Desktop\\Downtown_atlanta_night.jpg");

verbatim string literal:

System.Diagnostics.Process.Start(@"mspaint~C:\Users\Joshua Banks\Desktop\Downtown_atlanta_night.jpg");
kristian
so like this: System.Diagnostics.Process.Start("@mspaint~C:\Users\Joshua Banks\Desktop\Downtown_atlanta_night.jpg");
JB
not quite like that - I've updated my answer to demonstrate what I'm suggesting
kristian
still get an unrecognized escape sequence on on Downtown...when using the first method!
JB
check that all your slashes are escaped (I just saw that I missed one! - answer updated)
kristian
ok, i get a unhandled exception now, saying they can not find the file, when it is indeed here on the desktop!!
JB
would it have something to do with what type of file it is?
JB
Click **Start->Run**, and type the following: `mspaint~C:\Users\Joshua Banks\Desktop\Downtown_atlanta_night.jpg` Does the file open, or do you get an error? If you get an error, then no file exists at that path.
Michael Petrotta
I'm not familiar with that `mspaint~` syntax. Are you sure that's correct?
Michael Petrotta
tried that and yes sir it opens!!
JB
thas wat it was....mspaint was there from a previous way of loading an image...take away mspaint and it works!!!
JB
Thank You Kristian and Mr. Petrotta!!!
JB