How can i point to a default image in my C# application

I have a default image i want to use in C# application

I stored  the default image  in c:\crystal\images\defaultimage.png

I am trying to point to  it in my application as my default image but

somehow pointing  to the file with pbxPhoto.Image = ("C:\Crystal\Images\defaultimage.png");

 gives a syntax error (see attached)

Please note that i am getting the error in the code even before running

How can i resolve this error
Olukayode OluwoleSystems AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tapan PattanaikSenior EngineerCommented:
what error you are getting ?
Olukayode OluwoleSystems AnalystAuthor Commented:
If you look at the attached file you will see the  slash character between the folders

being flagged.

This is more like a syntax error and of course i cant run with the error


The backslash is an escape character in C#.  You need to add either a string literal indicator at the front of the string:
pbxPhoto.Image = (@"C:\Crystal\Images\defaultimage.png");

Open in new window

Or, use an extra backslash -
pbxPhoto.Image = ("C:\\Crystal\\Images\\defaultimage.png");

Open in new window

That being said a better option would be using the image as an embedded resource; that is unless the user can choose a different image.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

David Johnson, CD, MVPRetiredCommented:
either use your appsettings or copy the image to your source directory and then use a relative path from there
Olukayode OluwoleSystems AnalystAuthor Commented:
I have tried both options with the 2 statements

pbxPhoto.Image = Image.FromFile("C:\\Crystal\\Images\\defaultimage.png");
pbxPhoto.Image = Image.FromFile(@"C:\Crystal\Images\defaultimage.png");

I got the same error  File not Found (see attached)

Error Screen form the 2 Options provided
Even though the file exists.

What could I be doing wrong

Olukayode OluwoleSystems AnalystAuthor Commented:
Thanks for the effort.
I would have loved to listen to the UTube video but there is no voice

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.