1
votes

I am using Open XML SDK to add a serial number to each document that the user will download.

This is the code:

public static void OpenAndAddTextToWordDocument(string filepath, string txt)
{
    // Open a WordprocessingDocument for editing using the filepath.
    WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true);

    // Assign a reference to the existing document body.
    Body body = wordprocessingDocument.MainDocumentPart.Document.Body;

    // Add new text.
    Paragraph para = body.AppendChild(new Paragraph());



    Run run = para.AppendChild(new Run());
    run.AppendChild(new Text(txt));

    DocumentWatermarkTest.AddWaterMark(wordprocessingDocument);

    // Close the handle explicitly.
    wordprocessingDocument.Close();
}
protected void Button1_Click1(object sender, EventArgs e)
{
    string strDoc = @"C:\Users\xxx\Desktop\2138-1.doc";
    string strTxt = "Serial number: 23jl4hk52345h32jkl";
    OpenAndAddTextToWordDocument(strDoc, strTxt);
}

Now I need to prevent the user to delete the serial number when he opens the doc.

I read in the Open XML SDK 2.0 FAQ:

Open XML SDK only support features to protect a document such as preventing the sheet from being edited in UI

However, it does not explain how you do it.

1

1 Answers

0
votes

You can create a content place holder (tag) through Developer tab from microsoft word. In the properties of this tag you can restrict user for "Content cannot be edited" also "Content control cannot be deleted". Now you can access this Content Place Holder with its tag name programatically and can place your serial number inside.