0

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();
4
  • 1
    Windows filesystems don't support versioning directly. You can use some container which does support versioning, but then you'd need to expose the files to the OS in some way. Commented Apr 23, 2013 at 13:25
  • So I would be forced to use a config file or some sort of exterior versioning file? I also have the ability to do this in Java, so I looked into using the UserDefinedFileAttributeView interface, but after the version is created on the file, Java seems to be the only thing that can view this version. I can't look at the file details to view the version I appended to the file. Commented Apr 23, 2013 at 13:37
  • Why not tie in to a version control system? Commented Apr 23, 2013 at 14:04
  • I think a version control system would do the trick, but I think it's overkill for this solution. These files will only be downloaded once, or when they are updated, and there won't be too many of them. Updates to these files should be rare... Commented Apr 23, 2013 at 14:06

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks d.popov, I'll have to weigh my options because we didn't want to have a seperate file for versioning if it wasn't necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.