5

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?

2
  • 1
    you'll probably end up saving the version inside the file, as a line of text. Commented Aug 22, 2012 at 13:10
  • Hi, this is actually a special file that needs content formatted in a specific way, so i may not be able to have special version info in the text file itself. Thanks for your answer. Commented Aug 22, 2012 at 13:15

4 Answers 4

4

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

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

Comments

3

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.

Comments

2

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.

3 Comments

Hi, this is actually a special file that needs content formatted in a specific way, so i may not be able to have special version info in the text file itself. Thanks for your answer.
@user1202434: if you can't change the format of the file, there is another option (not sure if it fits your requirements) is creating your format with (say) zipped folder. So you can include a manifest with whatever info you want. Like, for example, MS DOCX format works (it's a simple zipped folder with a lot of files inside).
thanks for the suggestion. Ill have to see if that works for me..let me try.
1

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.

2 Comments

Thank you for the answer...learn something new everyday. Never knew about "ADS" before today.
@user1202434: Glad you learned something! That's why I mentioned it. :) Btw, that's also how Explorer stores Summary information about some files... they're useful in some cases, but you have to be aware that they might be lost across backups/file copies/etc., and that it won't work if the user is using a different file system. It's usually a risky solution unless you know exactly what you're doing... also be aware that .NET may not support this out of the box, I don't know.

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.