0

Good day! I have some file called "*.dat" with text into it. So, i try to create attribure "Version" ,but don't know how. Can i do it via c#? Can you write some examples?

Such like this?

File.SetAttributes(path, attributes);

Thank you!

user2545071
  • 1,408
  • 2
  • 24
  • 46
  • What is your goal? See the version in file properties? Or just save the metadata anywhere? Either way, you should probably consider a simpler alternative like embedding the data *inside* the file - it will be much more resilient to actions like web download, email attachment and moving between different file systems (many USBs are FAT32, for example) – Kobi Jun 02 '14 at 12:50

4 Answers4

3

You can't. The only values allowed are from the list here

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
  • 4
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Ňɏssa Pøngjǣrdenlarp Jun 02 '14 at 13:11
  • Links to MSDN are very likely one of the most stable out there, so I wouldn't lose my sleep over it. – Otávio Décio Jun 02 '14 at 13:15
3

You're probably struggling because you can't add arbitrary information into a file. There are a known set of attributes you can change using the FileAttribute properties

What you would normally do is provide some information at the start of your file, typically called the file header. This then allows a custom reading implementation to read out the version, without having to read the rest of the file. This is quite standard practise with all the files you're used to, for example a WAV audio file:

enter image description here

Ian
  • 33,605
  • 26
  • 118
  • 198
0

The attributes you can change here are the NTFS attributes. Details here: http://msdn.microsoft.com/en-us/library/system.io.fileattributes%28v=vs.110%29.aspx

Version is a resource embedded in an executable file. A similar question was asked here: How do I set the version information for an existing .exe, .dll?

Community
  • 1
  • 1
David Crowell
  • 3,711
  • 21
  • 28
0

reating "custom" file attributes is not allowed.

You can only set one of the FileAttributes .

Example:

File.SetAttributes(@"C:\myfile.txt", FileAttributes.Hidden);
quantdev
  • 23,517
  • 5
  • 55
  • 88