How can I Access and modify custom attributes of a file

Posted on 2009-02-13
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
    LVL 2

    Expert Comment


                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

    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
    LVL 26

    Expert Comment

    by:Anurag Thakur
    LVL 26

    Accepted Solution


    Author Comment

    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

    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
    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

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C# Help from Top Experts

    Solve your toughest problems, fast.
    C# experts are online now and ready to help you.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    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…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now