Click here to Skip to main content
15,891,876 members
Articles / Productivity Apps and Services / Microsoft Office

Hiding and Storing/caching of Application Specific data in MS Word 2003 documents

Rate me:
Please Sign up or sign in to vote.
3.54/5 (8 votes)
9 Oct 2008CPOL8 min read 29.1K   512   18  
Proof of concept on how the application specific (small/large amount of) data can be stored in ms word document as well as how it can be made hidden from end user’s eye.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;


namespace Common
{
    public class FileOperation
    {
        [DllImport("FileStorage.dll", CharSet = CharSet.Unicode)]
        public static extern Boolean AddDataToFile(string fileName, int typeOfData, string data, Int32 officeFile);
        [DllImport("FileStorage.dll", CharSet = CharSet.Unicode)]
        public static extern Boolean ReadDataFromFile(string fileName, int typeOfData, string data, UInt32 datasize, Int32 officeFile);

        public Boolean AddData(string fileName, int typeOfData, string data)
        {
            //Adds the DocumentID in the file specified by fileName by calling 
            //AddDataToFile() which is exported by FileStorage.dll
            
            Boolean retVal = false;
            try
            {
                retVal = AddDataToFile(fileName, typeOfData, data, 1);
            }
            catch (Exception e)
            {
            }
            finally
            {
            }
            return retVal;
        }

        public Boolean ReadData(string fileName, int typeOfData, ref string data, UInt32 datasize)
        {
            //Reads the DocumentID in the file specified by fileName by calling 
            //ReadDataFromFile() which is exported by FileStorage.dll
            Boolean retVal = false;
            char[] temp = new char[260];
            data = new string(temp);
            try
            {
                retVal = ReadDataFromFile(fileName, typeOfData, data, 260, 1);
                data = data.Replace('\0', ' ');
                data = data.Trim();
            }
            catch (Exception e)
            {
            }
            finally
            {
            }
            return retVal;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions