Click here to Skip to main content
15,888,968 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.Windows.Forms;

namespace DocumentIDReader
{
    static class Program
    {
        public const int STRINGDATA_DOCUMENTID = 100;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        public static void DisplayDocumentID(string documentName)
        {
            bool documentIDExists = false;
            FileOperation fileOperation=new FileOperation();
            string DocumentID=String.Empty;
            documentIDExists = fileOperation.ReadData(documentName, STRINGDATA_DOCUMENTID, ref DocumentID, 256);
            if (documentIDExists)
            {
               // MessageBox.Show("DocumentID Found ! \n ____________________________________________\n\n" + "ID : " + DocumentID, "Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MessageBox.Show(DocumentID);
            }
            else
            {
              //  MessageBox.Show("DocumentID Not Found !! " + DocumentID, "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                MessageBox.Show("DocumentID not found");

            }
        }

        public static void AddDocumentID(string documentName)
        {
            Boolean success = false;
            FileOperation fileOperation = new FileOperation();
            string DocumentID = Guid.NewGuid().ToString();

            success = fileOperation.AddData(documentName, STRINGDATA_DOCUMENTID, DocumentID);
            if (success==true)
                MessageBox.Show("DocumentID added ");
            //MessageBox.Show("DocumentID added ! \n ____________________________________________\n\n" + "ID : " +DocumentID,"success",MessageBoxButtons.OK,MessageBoxIcon.Information);
            else
                MessageBox.Show("Failed");
                //MessageBox.Show("Failed", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }
    }
}

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