gwin003
gwin003

Reputation: 7982

C# Simple File Versioning

Is there a .NET supported way of programmatically versioning basic text, excel, word, etc. files in the file system?

More specifically, I am attempting to add a file version attribute to a Crystal Reports file that is streamed from a Server to the Client when the client requests to run a report. FileVersionInfo only supports reading the file version, and File.GetAttributes only gets things like Hidden, Readonly, etc.

Edit: Note that I do not need to keep old versions of these files on the client. I can delete them and replace them with the newer version of the report file. I just need a way to persist the file version on the client side.

string path = @"C:\myReport.rpt";

FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(path);

Console.WriteLine("File: " + myFileVersionInfo.FileDescription + 
                  '\n' + "Version: " + myFileVersionInfo.FileVersion);

if(File.Exists(path))
{
    var fileAttributes = File.GetAttributes(path);
}
Console.ReadKey();

Upvotes: 0

Views: 4294

Answers (1)

d.popov
d.popov

Reputation: 4255

Plain files does not have these attributes. You will have to implement them externaly. this question is asked also here

According to MSDN:

Version resources are typically specified in a Win32 resource file, or in assembly attributes. For example the IsDebug property reflects the VS_FF_DEBUG flag value in the file's VS_FIXEDFILEINFO block, which is built from the VERSIONINFO resource in a Win32 resource file. For more information about specifying version resources in a Win32 resource file, see "About Resource Files" and "VERSIONINFO Resource" in the Platform SDK. For more information about specifying version resources in a .NET module, see the Setting Assembly Attributes topic. MSDN

So, there is some native way to store attributes for every file in a separate 'resource' file, but it will include some native method calls, and a .net warper class.

Upvotes: 2

Related Questions