Question

I am creating a file using:

File.WriteAllText(FILEPATHNAME, "SOME VALUE");

When creating a file, is it possible to specify a version programmatically? So that if someone were to use FileVersionInfo object they would get the version I specified?

Was it helpful?

Solution

No, there is no way to write file version in that way, nor that I'm aware of, honestly.

Possible option is:

Write file version into the file itself within some formatted data.

The most common approach I see, is writing into the beginning of the file or on the first line of the file. So you can fast access that information and decide either process with reading or not.

OTHER TIPS

The FileVersionInfo is a binary resource that can be stored in an executable file. However, you are writing a text file and those files cannot contain binary resources. Asking for the version (as defined by FileVersionInfo) of a text file does make sense

Unfortunately, it is not possible. Version information is an embedded resource attached to a file and only binary files can have embedded resources.

See the remarks section of FileVersionInfo Class for more information.

As an alternate approach, you can create an additional text file for each text file you are writing containing the version information.

If you really really cannot enter the version into the file itself, maybe try putting the version in an NTFS "alternate data stream" (ADS).

You'll need to know what you're doing though, since that has its own gotchas.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top