Question

I'm using a SharePoint (2013) event receiver to monitor when files are added to the document library. Every time a file is checked in, if its an MS office document, I'd like to read its custom properties and modify them as necessary (Basically, I'd like to keep their history in-file).

I'm able to do this for recent office documents (2007 onward) using openXML. A small example to show how I'm reading a .docx file (From an SPFile) is :

    SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            byte[] byteArray = File.OpenBinary();
            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);
                try
                {
                    using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(mem, true))
                    {
                        CustomFilePropertiesPart cp = wordDoc.CustomFilePropertiesPart;

That seems to work great, and later on I'm able to write to the file using savebinary after modifying the custom properties.

My problem is that I'd like to be able to do the same for office 2003 documents (.doc, .xls, .ppt). I found DSOFile, but the problem is that I can't use the standard 'open' function to access the file since I'm on a server.

My question is - How can I read and write the custom properties of office 2003 .doc/.xls/.ppt in a Sharepoint farm solution in C#?, ideally using DSOFile but I'd be open to any solutions.

Thanks in advance and please let me know if any additional information would prove useful.

Was it helpful?

Solution

Looks like I was able to answer my own question and wanted to share that answer for anyone else that may come along.

When you load a file in SharePoint to an SPFile, you can access File.Properties which is an array that actually contains the custom properties for binary office files. You can use File.AddProperty to include new properties, or simply set them like you'd set any array, with key being property name. Running File.Update() will sync the file properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top