We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


How can I Access and modify custom attributes of a file

cintra asked
Medium Priority
Last Modified: 2012-06-27
Hi all,

I'm building a little application to manage some files over a network with many users, the idea is that I wan't to prevent more than one person accessing the file at one time. All these files have the same name (but will sit in different folders) so I need to add a 'Tag' or 'Meta Data' to the file to allow me to identify it.

Through Windows you can right click on a file, Properties and Summary and then you can type in values to attach to the file. I need to access and modify this using C# has anyone ever tried this before??

Any help would be great!!
Watch Question

            var stream = new FileStream("<fullpath>", FileMode.Open, FileAccess.Read, FileShare.None);

//use your file it, it'll be locked to all others applications



Thanks, but maybe I didn't explain myself properly. Because all the files will be downloaded to each of the clients when they run this application - the first thing I need to is to upload them back to the server. To find out which folder I need to upload the files to I need to add some extra data to the file like a tag or something.

Is it possible to set an attribute of the file to hold this information so that I when the file is on the client I know where it came from?

I noticed when using Windows XP I can manually add information to a file by right clicking on it, selecting Properties and Summary - I can then enter data that attaches itself to the file, this would do what I need if I could access it programatically

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thanks again but not quite what I'm after...

The problem with that code (below) is it allows you to change the readonly attribute of the file, which is great, but what I need to do is attach a string as an attribute to allow me to identify the file and know where it has come from.

Kind of like a custom attribute.

                If (Filename.Attributes And FileAttributes.ReadOnly) Then
                    Filename.Attributes = (Filename.Attributes And Not FileAttributes.ReadOnly)
                End If
            Catch E As Exception
                Console.WriteLine("Error changing attribute for {0}", Filename.FullName)
                Console.WriteLine("Error: {0}", E.Message)
            End Try

Open in new window


That second link you sent me seems like its going to do the trick, only little problem and maybe its just me being stupid but he does mention having to reference a DLL - how do you this?

I've downloaded the DSOFile thing and it contains a dll but not sure how to to include it.

Any Ideas?
Anurag ThakurTechnical Manager

install the exe and the right click on the project and select add references and find the reference for Microsoft Developer Support OLE File Property in either .net section or com section
How about this ... when the file gets down to the users machine generate a small 8 byte text file with a code in it. Then run the dos command  copy clientfile.file + code.txt clientfile.file

What this does is append the text file to the end of your file.

You then upload the file and look at the last 8 bytes of the file and Voila there is your code no messing with attributes.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.