In a SharePoint 2010 project of mine, i have to insert watermark in a word file using Event Receive. To do that i am trying to use Microsoft.Office.Interop.Word namespace. It do the job. But to insert the watermark to the document file, it need to open the file. And to do that this function is called: WordApp.Application.Documents.Open(fileName);

And when it calls the function, it asks for credentials. But as my project requirements, i can't ask credentials on that time.

So it there any way to prevent SharePoint asking for credentials in this step? Or is their any other way to insert watermark in a word document without asking for credentials.

I am giving the function here which is used to insert watermark in word document which i used in my project.

public void AddWatermarkToFile(string text, string fileName, SPFolder currentListItem, SPWeb spWeb)
    // word app
    ApplicationClass WordApp = null;
    // word document
    Document document = null;
    Microsoft.Office.Interop.Word.Shape nShape = null;
        currentListItem.ParentWeb.AllowUnsafeUpdates = true;
        WordApp = new ApplicationClass();
        WordApp.Visible = true;
        WordApp.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;

        Uri destUri = new Uri(fileName);
        WebRequest req = WebRequest.Create(destUri);
        req.Credentials = CredentialCache.DefaultCredentials;
        // open
        document = WordApp.Application.Documents.Open(fileName); 
        // add watermark
        foreach (Section section in document.Sections)
            nShape = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, text, "Tahoma", 9, MsoTriState.msoCTrue, MsoTriState.msoFalse, 0, 0);
            nShape.Fill.Visible = MsoTriState.msoTrue;
            nShape.Line.Visible = MsoTriState.msoFalse;
            nShape.Fill.ForeColor.RGB = (Int32)WdColor.wdColorGray65;
            nShape.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
            nShape.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
            // center location
            nShape.Left = (float)WdShapePosition.wdShapeCenter;
            nShape.Top = (float)WdShapePosition.wdShapeCenter;
        // save 
        currentListItem.ParentWeb.AllowUnsafeUpdates = false;
        // close excel document & application
        if (document != null)
            catch { }
        if (WordApp != null)
            catch { }
  • From where you are opening a word document? like from computer or from within SharePoint?
    – Hardik
    Commented Mar 15, 2016 at 9:50
  • The word document is already on SharePoint document library in server. Commented Mar 15, 2016 at 10:51

1 Answer 1


I solved problem as the requirement, but in a unusual way. Though it is not the best solution.

As i can't solve the problem to prevent SharePoint asking for credentials in the time of open a word file programmatically and to insert Watermark into the file, need be opened. So i download the files on users computer, insert watermark and upload to the SharePoint library again programmatically.

This will help me for now. But as this not the best solution, if anyone has any please let me know.

  • 1
    Plz accept your own answer as answer, so the question will not appear in Unanswered Questions List
    – P S
    Commented Mar 29, 2016 at 12:21
  • was expecting a better solution. bt now i selected mine as answer. Commented Mar 29, 2016 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.