How can I Access and modify custom attributes of a file

Posted on 2009-02-13
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!!
Question by:cintra

Expert Comment

ID: 23633559

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

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


Author Comment

ID: 23634027
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 26

Accepted Solution

Anurag Thakur earned 2000 total points
ID: 23634073

Author Comment

ID: 23634126
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


Author Comment

ID: 23634315
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?
LVL 26

Expert Comment

by:Anurag Thakur
ID: 23635001
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
LVL 12

Expert Comment

ID: 23638270
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.


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question