Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have windows forms application. In that I used images dynamically which are store in 'Resources' folder. I deployed the app and uses in my PC, it working great. But when I installed it on my friends computer. When I start it there 'JIT' is throwing an error. The error contains 'Resources' folder images.
Kindly help me to sort out this.
My Code is like this:
C#
private void Hurf_Load(object sender, EventArgs e)
       {
           pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\alif.gif");
           pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\Allah.gif");
           pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\Allah.gif");
           pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\ALLAHH.jpg");
           label1.Text = "ا";
           next.Text = "ب";
           prev.Text = "ی";
       }

       private void next_Click(object sender, EventArgs e)
       {

           if (label1.Text == "ا")
           {
               pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\circle_baa.jpg");
               pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\baab.jpeg");
               pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\BAB.jpg");
               pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\DOOR.jpg");
               label1.Text = "ب";
               next.Text = "ت";
               prev.Text = "ا";

           }
           else if (label1.Text == "ب")
           {
               pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\circle_taa.jpg");
               pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\turab.jpg");
               pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\تراب.jpg");
               pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\SOIL.jpg");
               label1.Text = "ت";
               next.Text = "ث";
               prev.Text = "ب";
           }
           else if (label1.Text == "ت")
           {
               pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\circle_thaa.jpg");
               pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\fuit.jpg");
               pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\SAMAR.jpg");
               pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\FRUIT.jpg");
               label1.Text = "ث";
               next.Text = "ج";
               prev.Text = "ت";
           }


I am getting error:
"Unhandled Exception has occured in your application"..............
"System.IO.FileNotFoundException: D:\islamic projects\Aleef\Aleef\Resources\alif.gif"

How to improve this code. Kindly Help.
Thanks & Regards,
Farhan
Posted
Updated 30-Apr-15 17:13pm
v2
Comments
Dave Kreskowiak 30-Apr-15 23:03pm    
What's the EXACT error message?
Farhan Bajrai 30-Apr-15 23:13pm    
sir added code and error msg in the question
gggustafson 1-May-15 0:10am    
Did you include all of the graphics files in your deployment. Your code references D:\islamic projects\Aleef\Aleef\Resources\. Do you create and populate that directory?
Farhan Bajrai 1-May-15 2:10am    
Actually, I am a beginner. Can you give me the process how to include all files, and is there any other process for inserting images which take Short Path. Because problem is arising in third party system.
@gggustafson.
gggustafson 1-May-15 10:18am    
There's nothing wrong with being a beginner. Fifty years ago, I was a beginner. Did you read Bill Woodruff's solution? The list of references he supplied is quite extensive. You should read the first two articles carefully. If you have questions after you read them, reply to this comment. I'll be glad to help you over the rough spots.

1 solution

Looks like you are using a hard-coded file-path to the images that is valid on your machine, and not valid on any other machine.

What you need to do is embed the images in your Application as resources.

Look at these CodeProject articles for examples of how to do that: [^].
 
Share this answer
 
Comments
gggustafson 1-May-15 10:18am    
+5
Farhan Bajrai 2-May-15 5:09am    
Thanks, these are very important links to me. In Sha Allah I will read and try to understand those. If any problem exists, I will ask.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900