I am trying to make a compression application. The current obstacle I am facing is that whenever I try to compress my file I take a byte array from the file and apply compression algorithm on the byte array itself because of which the metadata of file is lost.
Is there any method by which I can extract the metadata of a file on compression and later on extraction attach the metadata to the extracted file?
Visual Studio : VS2008
Framework : .Net 3.5
//creates new class of oledocumentproperties var doc = new OleDocumentPropertiesClass(); //open your selected file doc.Open(@"C:\Users\ABC\Desktop\Test\1.jpg", false, dsoFileOpenOptions.dsoOptionDefault); //you can set properties with summaryproperties.nameOfProperty = value; for example doc.SummaryProperties.Company = "lol"; //Line 8 : Shows error doc.SummaryProperties.Author = "me"; //after making changes, you need to use this line to save them doc.Save();
I get the following error on Line 8
The name is not valid. (Exception from HRESULT: 0x800300FC (STG_E_INVALIDNAME))
Are you sure that the Company
property exists in your file metadata?
Try using a known existing property in the metadata of the file you're trying to access, as the ones that are used in the example may just not exist.
As for saving the properties, you can access some basic global ones like CreationTime
and LastAccessTime
from the System.IO.FileInfo
object.
This article seems to describe a method through which you can get more specific properties from files, such as the Camera
and CameraManufacturer
properties (that isn't identical to the one from the StackOverflow question) like so:
using System;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using Microsoft.WindowsAPICodePack.Shell;
using System.Diagnostics;
class Program {
void getProperty() {
var cameraModel = GetValue(picture.Properties.
GetProperty(SystemProperties.System.Photo.CameraModel));
}
}
with GetValue being:
private static string GetValue(IShellProperty value)
{
if (value == null || value.ValueAsObject == null)
{
return String.Empty;
}
return value.ValueAsObject.ToString();
}
User contributions licensed under CC BY-SA 3.0