2

I ran into a problem this week regarding the Windows Shell Property System when applied to TIFF/TIF files. I'm using Microsoft.WindowsAPICodePack 1.1.0.0 to access the property system.

When adding properties, the file gets corrupted because it seems to get stored where the first IFD pointer would be expected. Now I'm not sure it simply inserts itself at the 5th byte, after the file header (0x49 0x49 0x2A 0x00), of if it overwrites any existing data. Additionally, when comparing the hexadecimal of the IDF entries headers, the bytes looks different. Now when I say corrupted, it is only when programmatically opening the file as a byte stream, not knowing if the file has a property system container added to it. It opens fine in Windows Image Preview, but not in the software my clients are using to view TIFF files.

Here's how I'm adding the properties (as an array of key=value strings).

    public void SetFileTag(string fileName, string tagName, string tagValue)
    {
        try
        {
            using (var shellFile = ShellFile.FromFilePath(fileName))
            {
                var keywords = shellFile.Properties.System.Keywords.Value;
                var keyValue = string.Concat(tagName, "=", tagValue);
                var list = keywords == null ? new List<string>() : new List<string>(keywords);

                if (list.Contains(keyValue))
                {
                    return;
                }

                list.Add(keyValue);

                using (var writer = shellFile.Properties.GetPropertyWriter())
                {
                    writer.WriteProperty(shellFile.Properties.System.Keywords, list.ToArray(), true);
                    writer.Close();
                }
            }
        }
        finally
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }

I looked in the code pack for anything available to entirely remove the properties, but I can't find any method to do so, I can only remove the keywords value. Anyone would have an idea on how to perform this? It doesn't have to be .NET code, it can very well be a command-line tool or win32 code.

RickNo
  • 403
  • 5
  • 12
  • This seems impossible, even extracting each frame to a separate file seems to create a different byte structure than the original file. I was able to restore all file by converting them to PDF, which was a good solution in our situation. – RickNo Jan 27 '16 at 15:38

0 Answers0