title: VB.NET Renaming File and Retagging / Edit Image MetaData / Meta Tags
body: <p><strong>Clarifiration:</strong></p>
  
  <p><em>How do I Edit and Save Image EXIF / Metadata / FileInfo without using an external DLL?</em></p>
  
  <p><strong>Project:</strong></p>
  
  <p>I'm building an app for personal use to rename, retag, and organize the apocalyptic quantity of images I host on my personal website. As I have been collecting funny pictures and such for several years, there is no real rhyme or reason to the file naming conventions. Ergo, Image0001.jpg needs to be renamed to a descriptive filename, and the Metadata fields need to be filled in.</p>
  
  <p><strong>The desired process will take an existing jpg, gif, png, tiff or bmp and do the following:</strong></p>
  
  <ol>
  <li>load image into memory</li>
  <li>convert bmp files to jpgs if needed (for a smaller file size, mostly)</li>
  <li>load image tags into ImageData Structure (see below)</li>
  <li>load file data into ImageData Structure (where needed)</li>
  <li>display image and tags for user to edit (In a Picture Box and several Text Boxes)</li>
  <li>allow editing of fields and renaming of the file</li>
  <li>write the changes to the image file</li>
  <li>go to next file.</li>
  </ol>
  
  <p>Example: </p>
  
  <ol>
  <li>Load Image0001.jpg. Populate ImageData Structure fields.</li>
  <li>Type in Description: "lolcat ceiling cat sends son".</li>
  <li>ImageData.FileName changed to "lolcat-ceiling-cat-sends-son.jpg".</li>
  <li>ImageData.Name, .Keywords, .Title, .Subject, and .Comments changed to "lolcat ceiling cat sends son".</li>
  <li>Save file with new filename and save all new tag fields.</li>
  </ol>
  
  <p>(Later, I will also be using SQL to build a referential database with links to the online copies of these files to allow for searching by keywords, subject, filename, etc, but that's another layer that's much easier than this one. At least to me.)</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>So far, several days of research have yielded almost no measurable progress. Information has apparently been inexplicably hidden behind a bunch of unexpected search keywords that I have not though to use for my searches. Any help would be appreciated.</p>
  
  <p><strong>Current Code as is:</strong></p>
  
  <pre><code>Imports System.IO
  Imports System.IO.Path
  Imports System.Drawing.Imaging
  Imports ImageData '(The Custom Structure below)'
  '*Also has a project level reference to the dso.dll referenced below.'
  
  Public Structure ImageData
          Shared FileAuthorAuthor As String
          Shared FileAuthorCategory As String
          Shared FileAuthorComments As String
          Shared FileAuthorCompany As String
          Shared FileAuthorDateCreated As DateTime
          Shared FileAuthorDescription As String
          Shared FileAuthorHeight As Decimal
          Shared FileAuthorHeightResolution As Decimal
          Shared FileAuthorImage As Image
          Shared FileAuthorKeywords As String
          Shared FileAuthorName As String
          Shared FileAuthorPath As String 'URL or IRL'
          Shared FileAuthorRead As Boolean
          Shared FileAuthorSubject As String
          Shared FileAuthorTitle As String
          Shared FileAuthorType As String
          Shared FileAuthorWidth As Decimal
          Shared FileAuthorWidthResolution As Decimal
  End Structure 'ImageData
  </code></pre>
  
  <p>And the current method for finding the data is:</p>
  
  <pre><code>Shared Function ReadExistingData(ByRef FileWithPath As String) As Boolean
  
          'Extract the FileName'
          Dim PathParts As String() = FileWithPath.Split("\") '"
          Dim FileName As String = PathParts(PathParts.Length - 1) 
          Dim FileParts As String() = FileName.Split(".")
          Dim FileType As String = FileParts(FileParts.Length - 1)
  
          'Create an Image object. '
          Dim SelectedImage As Bitmap = New Bitmap(FileWithPath)
  
          'Get the File Info from the Image.'
          Dim ImageFileInfo As New FileInfo(FileWithPath)
          Dim dso As DSOFile.OleDocumentProperties
          dso = New DSOFile.OleDocumentProperties
          dso.Open(FileWithPath.Trim, True, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess)
  
          ImageData.FileAuthor = dso.SummaryProperties.Author '* Requires dso.DLL'
          ImageData.FileCategory = dso.SummaryProperties.Category '* Requires dso.DLL'
          ImageData.FileComments = dso.SummaryProperties.Comments '* Requires dso.DLL'
          ImageData.FileCompany = dso.SummaryProperties.Company '* Requires dso.DLL'
          ImageData.FileDateCreated = ImageFileInfo.CreationTime
          ImageData.FileDescription = dso.SummaryProperties.Comments  '* Requires dso.DLL.'
          ImageData.FileHeight = SelectedImage.Height
          ImageData.FileHeightResolution = SelectedImage.VerticalResolution
          ImageData.FileImage = New Bitmap(FileWithPath)
          ImageData.FileKeywords = dso.SummaryProperties.Keywords '* Requires dso.DLL'
          ImageData.FileName = FileName
          ImageData.FilePath = FileWithPath
          ImageData.FileRead = ImageFileInfo.IsReadOnly
          ImageData.FileSubject = dso.SummaryProperties.Subject '* Requires dso.DLL'
          ImageData.FileTitle = dso.SummaryProperties.Title '* Requires dso.DLL'
          ImageData.FileType = FileType
          ImageData.FileWidth = SelectedImage.Width
          ImageData.FileWidthResolution = SelectedImage.HorizontalResolution
  
          Return True
  
  End Function 'ReadExistingData'
  </code></pre>
  
  <p><strong>Just a couple of the "Top Box" search hits I've reviewed:</strong></p>
  
  <ul>
  <li><p>The dso.DLL: Very Helpful, but undesirable. Requires external DLL.<br>
  [http://]www.developerfusion.com/code/5093/retrieving-the-summary-properties-of-a-file/</p></li>
  <li><p>Incomplete Data ~ Does not answer my questions<br>
  [http://]msdn.microsoft.com/en-us/library/xddt0dz7.aspx</p></li>
  <li><p>Requires external DLL<br>
  [http://]www.codeproject.com/KB/GDI-plus/ImageInfo.aspx</p></li>
  <li><p>External Software required<br>
  [http://]stackoverflow.com/questions/3313474/write-metadata-to-png-image-in-net</p></li>
  <li><p>Old Data ~  Visual Studio 2005 and .NET 2.0<br>
  [http://]www.codeproject.com/KB/graphics/MetaDataAccess.aspx</p></li>
  <li><p>Convert to BMP: Looks useful<br>
  [http://]www.freevbcode.com/ShowCode.Asp?ID=5799</p></li>
  </ul>