<p>I would like to write a small program in C# which goes through my jpeg photos and, for example, sorts them into dated folders (using MY dating conventions, dammit...). </p>

<p>Does anyone know a relatively easy way to get at the EXIF data such as Date And Time or Exposure programatically?
Thanks!</p>

[{'answer_id': 58662, 'author': 'goldenmean', 'author_id': 2759376, 'author_profile': 'https://Stackoverflow.com/users/2759376', 'pm_score': 3, 'selected': False, 'text': '<p>Getting EXIF data from a JPEG image involves:</p>\n\n<ol>\n<li>Seeking to the JPEG markers which mentions the beginning of the EXIF data,. e.g. normally oxFFE1 is the marker inserted while encoding EXIF data, which is a APPlication segment, where EXIF data goes.  </li>\n<li>Parse all the data from say 0xFFE1 to 0xFFE2 . This data would be stream of bytes, in the JPEG encoded file.  </li>\n<li>ASCII equivalent of these bytes would contain various information related to Image Date, Camera Model Name, Exposure etc...</li>\n</ol>\n'}, {'answer_id': 58669, 'author': 'idursun', 'author_id': 5984, 'author_profile': 'https://Stackoverflow.com/users/5984', 'pm_score': 3, 'selected': False, 'text': '<p>Image class has PropertyItems and PropertyIdList properties. You can use them.</p>\n'}, {'answer_id': 156640, 'author': 'Dave Griffiths', 'author_id': 15379, 'author_profile': 'https://Stackoverflow.com/users/15379', 'pm_score': 6, 'selected': True, 'text': '<p>Check out this <a href="https://www.drewnoakes.com/code/exif/" rel="noreferrer">metadata extractor</a>. <strike>It is written in Java but has also been ported to C#.</strike> I have used the Java version to write a small utility to rename my jpeg files based on the date and model tags. Very easy to use.</p>\n\n<hr>\n\n<p><strong>EDIT</strong> <em>metadata-extractor</em> supports .NET too. It\'s a very fast and simple library for accessing metadata from images and videos.</p>\n\n<p>It fully supports Exif, as well as IPTC, XMP and many other types of metadata from file types including JPEG, PNG, GIF, PNG, ICO, WebP, PSD, ...</p>\n\n<pre><code>var directories = ImageMetadataReader.ReadMetadata(imagePath);\n\n// print out all metadata\nforeach (var directory in directories)\nforeach (var tag in directory.Tags)\n    Console.WriteLine($"{directory.Name} - {tag.Name} = {tag.Description}");\n\n// access the date time\nvar subIfdDirectory = directories.OfType&lt;ExifSubIfdDirectory&gt;().FirstOrDefault();\nvar dateTime = subIfdDirectory?.GetDateTime(ExifDirectoryBase.TagDateTime);\n</code></pre>\n\n<p>It\'s available via <a href="https://www.nuget.org/packages/MetadataExtractor/" rel="noreferrer">NuGet</a> and the <a href="https://github.com/drewnoakes/metadata-extractor-dotnet" rel="noreferrer">code\'s on GitHub</a>.</p>\n'}, {'answer_id': 636622, 'author': 'Joel in Gö', 'author_id': 6091, 'author_profile': 'https://Stackoverflow.com/users/6091', 'pm_score': 3, 'selected': False, 'text': '<p>Here is a link to another <a href="https://stackoverflow.com/questions/280003/how-do-i-retrieve-the-properties-of-a-photo-taken-on-a-digital-camera-using-net/636606#636606">similar SO question</a>, which has an answer pointing to this good article on <a href="http://www.vsj.co.uk/dotnet/display.asp?id=649" rel="nofollow noreferrer">"Reading, writing and photo metadata"</a> in .Net.</p>\n'}, {'answer_id': 1268857, 'author': 'Jan Zich', 'author_id': 15716, 'author_profile': 'https://Stackoverflow.com/users/15716', 'pm_score': 6, 'selected': False, 'text': '<p>As suggested, you can use some 3rd party library, or do it manually (which is not that much work), but the simplest and the most flexible is to perhaps use the built-in functionality in .NET. For more see:</p>\n\n<ul>\n<li><p><a href="http://msdn.microsoft.com/en-us/library/system.drawing.image.propertyitems.aspx" rel="noreferrer">System.Drawing.Image.PropertyItems</a> Property</p></li>\n<li><p><a href="http://msdn.microsoft.com/en-us/library/system.drawing.imaging.propertyitem.aspx" rel="noreferrer">System.Drawing.Imaging.PropertyItem</a> Class </p></li>\n<li><p><a href="http://msdn.microsoft.com/en-us/library/xddt0dz7.aspx" rel="noreferrer">How to: Read Image Metadata</a></p></li>\n</ul>\n\n<p>I say "it’s the most flexible" because .NET does not try to interpret or coalesce the data in any way. For each EXIF you basically get an array of bytes. This may be good or bad depending on how much control you actually want.</p>\n\n<p>Also, I should point out that the property list does not in fact directly correspond to the EXIF values. EXIF itself is stored in multiple tables with overlapping ID’s, but .NET puts everything in one list and redefines ID’s of some items. But as long as you don’t care about the precise EXIF ID’s, you should be fine with the .NET mapping.</p>\n\n<hr>\n\n<p><strong>Edit:</strong> It\'s possible to do it without loading the full image following this answer: <a href="https://stackoverflow.com/a/552642/2097240">https://stackoverflow.com/a/552642/2097240</a></p>\n'}, {'answer_id': 7887165, 'author': 'smola', 'author_id': 205607, 'author_profile': 'https://Stackoverflow.com/users/205607', 'pm_score': 3, 'selected': False, 'text': '<p>You can use <a href="https://github.com/mono/taglib-sharp">TagLib#</a> which is used by applications such as <a href="http://f-spot.org/">F-Spot</a>. Besides Exif, it will read a good amount of metadata formats for image, audio and video.</p>\n\n<p>I also like <a href="https://code.google.com/p/exif-utils/">ExifUtils</a> API but it is buggy and is not actively developed.</p>\n'}, {'answer_id': 9123026, 'author': 'Kirk Broadhurst', 'author_id': 146077, 'author_profile': 'https://Stackoverflow.com/users/146077', 'pm_score': 2, 'selected': False, 'text': '<p>The command line tool <a href="http://www.sno.phy.queensu.ca/~phil/exiftool/" rel="nofollow">ExifTool by Phil Harvey</a> works with dozens of images formats - including plenty of proprietary RAW formats - and can manipulate a variety of metadata formats including EXIF, GPS, IPTC, XMP, JFIF.</p>\n\n<p>Very easy to use, lightweight, impressive application.</p>\n'}, {'answer_id': 63352062, 'author': 'Shoaib Khan', 'author_id': 11795958, 'author_profile': 'https://Stackoverflow.com/users/11795958', 'pm_score': 0, 'selected': False, 'text': '<p>Recently, I used this <a href="https://products.groupdocs.com/metadata/net" rel="nofollow noreferrer">.NET Metadata API</a>. I have also written a <a href="https://blog.groupdocs.com/2020/05/13/manage-exif-data-in-csharp-net-for-jpeg-png-tiff-webp-images/" rel="nofollow noreferrer">blog post</a> about it, that shows reading, updating, and removing the EXIF data from images using C#.</p>\n<pre><code>using (Metadata metadata = new Metadata(&quot;image.jpg&quot;))\n{\n    IExif root = metadata.GetRootPackage() as IExif;\n    if (root != null &amp;&amp; root.ExifPackage != null)\n    {\n        Console.WriteLine(root.ExifPackage.DateTime);\n     }\n}\n</code></pre>\n'}, {'answer_id': 74401570, 'author': 'Gray Programmerz', 'author_id': 14919621, 'author_profile': 'https://Stackoverflow.com/users/14919621', 'pm_score': 0, 'selected': False, 'text': '<p>fastest way is to use <a href="https://www.nuget.org/packages/WindowsAPICodePack-Shell/" rel="nofollow noreferrer">windows api codec</a> that doesn\'t open file and instead uses cached exif information</p>\n<pre><code>var prop = ShellFile.FromFilePath(f).Properties;\nvar Dimensions = prop.GetProperty(&quot;Dimensions&quot;).ValueAsObject.ToString(); \n//1280 x 800\n\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/58649', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6091/']