Hi,

I am attempting to iterate through all image files in a folder and it's subfolders to check for the EXIF property of DateTimeOriginal.

For the life of me I cannot seem to work out how do this, I can work it fine by just entering a single Path in the Bitmap but not when it comes to cycling through the entire directory.

This is the code I am playing around with:

///try
            ///{
                string[] filePaths = Directory.GetFiles(@"C:\Users\1CM69\Pics & Vids\Archives\Family\", "*.*", SearchOption.AllDirectories);
                ///foreach (string file in filePaths);
                Bitmap MyPhoto = new Bitmap(filePaths);
                const int IDDateTimeOriginal = 36867;
                PropertyItem TakenDate = MyPhoto.GetPropertyItem(IDDateTimeOriginal);
                Encoding ascii=Encoding.ASCII;
                string DateTaken=ascii.GetString(TakenDate.Value,0,TakenDate.Len-1);
                MessageBox.Show(DateTaken);

           /// }
            ///catch (ArgumentException) //if the property doesn't exists
            ///{ MessageBox.Show("no entry available"); }

As you can see, I have commented out some sections just for debugging purposes.

I think that the main issue is with the section:

new Bitmap(filePaths);

I have run out of ideas to solve this and any help would be appreciated.

Kindest regards..,

OK, a little more fiddling and I got this part to work somewhat:

try
            {
                string[] filePaths = Directory.GetFiles(@"C:\Users\1CM69\Pics & Vids\Archives\Family\", "*.*", SearchOption.AllDirectories);
                foreach (string file in filePaths)
                {
                    Bitmap MyPhoto = new Bitmap(file);
                    const int IDDateTimeOriginal = 36867;
                    PropertyItem TakenDate = MyPhoto.GetPropertyItem(IDDateTimeOriginal);
                    Encoding ascii = Encoding.ASCII;
                    string DateTaken = ascii.GetString(TakenDate.Value, 0, TakenDate.Len - 1);
                    MessageBox.Show(DateTaken);
                }

           }
            catch (ArgumentException) //if the property doesn't exists
            { MessageBox.Show("no entry available");
            }

The issue I have now is that as soon as it finds an image that does not have the existing property the Exception fires as it should and then stops without continuing through the rest of the files.
I need it to carry on regardless of exception.

Regards..,

I must be tired, I missed an obvious error, I just had to move the for loop:

string[] filePaths = Directory.GetFiles(@"C:\Users\1CM69\Pics & Vids\Archives\Family\", "*.*", SearchOption.AllDirectories);
            foreach (string file in filePaths)
            {
                try
                {


                    Bitmap MyPhoto = new Bitmap(file);
                    const int IDDateTimeOriginal = 36867;
                    PropertyItem TakenDate = MyPhoto.GetPropertyItem(IDDateTimeOriginal);
                    Encoding ascii = Encoding.ASCII;
                    string DateTaken = ascii.GetString(TakenDate.Value, 0, TakenDate.Len - 1);
                    MessageBox.Show(DateTaken);
                }


                catch (ArgumentException) //if the property doesn't exists
                {
                    MessageBox.Show("no entry available");
                }

            }

All working now.

Regards..,

Glad to know that you work it out yourself, and it was pretty quickly! =)

Pls, just mark the tread as solved =)

This question has already been answered. Start a new discussion instead.