Creating .exe file containing app data + PictureBox problem

Posted by Roydoron under C# on 3/28/2013 | Points: 10 | Views : 828 | Status : [Member] | Replies : 3
Hello Everyone,

I have two problems with my Winforms application.

In my app im reading from a folder that contains 1000 photos.

1. Each time Im running my app, I programed it to read the photos stored in a specific folder and put them in a DB (Dictionary<string, Image>), using:
            dI = new DirectoryInfo(@"C:\Users\Me\Desktop\Photos");
fileInfos = dI.GetFiles("*.jpg", SearchOption.TopDirectoryOnly);
foreach (FileInfo fi in fileInfos)
{
DB.Add(Path.GetFileNameWithoutExtension(fi.FullName), Image.FromFile(fi.FullName));
}


but when im trying to place a photo in a pictureBox using:
pictureBox4.BackgroundImage =  DB["PhotoName"];


It shows nothing, blank.

that's a drawback, CAUSE,

2. I want to use this app in other computers using only the .exe file that stored in the ..\bin\debug\
without each time changing the path the photos are stored...

So, how do I create an .exe file for my app that already has all the photos? without worring about them? (problem no' 2)

And, how to make sure the photos are shown (problem no' 1)

Thank you all!




Responses

Posted by: Jitendrasoft09 on: 3/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello,
dI = new DirectoryInfo(@"C:\Users\Me\Desktop\Photos");- If you want make dynamic path use this @"~\servername\photos\".
pictureBox4.BackgroundImage = DB["PhotoName"];-here need to specify DB["PhotoName"]+".jpg";- photos are added without extension into DB, so need to specify the extension at the time of loading into picturebox.

As photos are adding into dictionary class with key value at the time of deployment all photos to be stored in dictionary, so photos will be be displayed without worry.

Jitendra Kumar
If my post helps you, plz mark as an answer.

Roydoron, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Roydoron on: 3/28/2013 [Member] Starter | Points: 25

Up
0
Down
hey jitendra kumar,

First, the dynamic you proposed is not working. I put the photos folder in c:\ and tried
 @"~\photos\
and its not working...
Second,
pictureBox4.BackgroundImage = DB["PhotoName"];-here need to specify DB["PhotoName"]+".jpg";
is not working either, I cant have a string concat to an image..

any other thought?



Roydoron, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 3/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Dear Roydron,

DB (Dictionary<string, Image>)- It might be the issue of Dictionary as you are using the picture on the Dictionary class, plz check on Dictionary part to resolve the issue.

Jitendra Kumar
If my post helps you, plz mark as an answer.

Roydoron, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response