Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7528545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:24:37+00:00 2026-05-30T04:24:37+00:00

I have a file test.docx with 3 page sections, and each section is unlinked

  • 0

I have a file “test.docx” with 3 page sections, and each section is unlinked from the previous page. Now I want to be able to set a different background/watermark for each section. I just don’t know how to select the other 2 sections (or.. not the first one).

I tried it like this:

Application nWord = new Application();
object oMissing = System.Reflection.Missing.Value;
object fileName = @"E:\test.docx";
Document nDoc = nWord.Documents.Open(ref fileName, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
Shape nShape = null;

for (int i = 0; i < nDoc.Sections.Count; i++)
{
    nShape =
    nDoc.Sections[i].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(Microsoft.Office.Core.MsoPresetTextEffect.msoTextEffect1,
    "TEXT" + i.ToString(), "Arial", (float)36, Microsoft.Office.Core.MsoTriState.msoTrue,
    Microsoft.Office.Core.MsoTriState.msoFalse, 0, 0, ref oMissing);

    nShape.Fill.Visible =
    Microsoft.Office.Core.MsoTriState.msoTrue;
    nShape.Line.Visible =
    Microsoft.Office.Core.MsoTriState.msoFalse;
    nShape.Fill.Solid();
    nShape.Fill.ForeColor.RGB = (Int32)WdColor.wdColorGray20;
    nShape.RelativeHorizontalPosition =
    WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
    nShape.RelativeVerticalPosition =
    WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
    nShape.Left = (float)WdShapePosition.wdShapeCenter;
    nShape.Top = (float)WdShapePosition.wdShapeCenter;
}
nWord.Visible = true;

but it just drops all 3 watermarks on the first section.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:24:38+00:00Added an answer on May 30, 2026 at 4:24 am

    I actually found a work around, after 3 days of searching and discussing. Here’s my solution:

    //initialize
    Application WordApp = new Application();
    Document adoc = WordApp.Documents.Add();
    Selection selection = adoc.ActiveWindow.Selection;
    Shape wmShape;
    object missing = System.Reflection.Missing.Value;
    object linktofile = false;
    object savewithdocument = true;
    object CurrentPage = WdFieldType.wdFieldPage;
    object TotalPages = WdFieldType.wdFieldNumPages;
    
    //load background images
    List<string> images = new List<string>();
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Koala.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Hydrangeas.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg");
    images.Add(@"C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg");
    
    //create all sections
    object breaktype = WdBreakType.wdSectionBreakNextPage;
    for (int i = 0; i < images.Count - 1; i++)
    {
        adoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
        selection.InsertBreak(ref breaktype);
        adoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
        selection.HeaderFooter.LinkToPrevious = false;
    }
    
    //set background images
    for (int i = 0; i < adoc.Sections.Count; i++)
    {
        //select section header
        adoc.Sections[i+1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Select();
    
        //insert pagenumbers
        adoc.ActiveWindow.ActivePane.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
        selection.TypeText("Pagina ");
        selection.Fields.Add(selection.Range, ref CurrentPage, ref missing, ref missing);
        selection.TypeText(" van ");
        selection.Fields.Add(selection.Range, ref TotalPages, ref missing, ref missing);
    
        //insert shape
        wmShape = selection.InlineShapes.AddPicture(images[i], ref linktofile, ref savewithdocument).ConvertToShape();
    
        //modify shape properties
        wmShape.Select(ref missing);
        wmShape.Name = "WordPictureWatermark862903805";
        wmShape.PictureFormat.Brightness = (float)0.5;
        wmShape.PictureFormat.Contrast = (float)0.5;
        wmShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoFalse;
        wmShape.Height = WordApp.InchesToPoints((float)11.7);
        wmShape.Width = WordApp.InchesToPoints((float)8.3);
        wmShape.WrapFormat.AllowOverlap = -1;
        wmShape.WrapFormat.Side = WdWrapSideType.wdWrapBoth;
        wmShape.WrapFormat.Type = WdWrapType.wdWrapBehind;
        wmShape.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
        wmShape.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
        wmShape.Left = (float)WdShapePosition.wdShapeCenter;
        wmShape.Top = (float)WdShapePosition.wdShapeCenter;
    
    }
    
    WordApp.Visible = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a test file that has many lines, each line looks something like:
I have a test file that contains 1,2,3 2,3,4 5,6,7 I want to insert
I have a file test.xml that I want to POST up to a URL
I have a file test.php in that i want to add a PHP script
i have some file test.php <?PHP $config_key_security = test; ?> and i have some
Let's say I have a file called test.txt within the package com.test.io within my
I have a test file that contains tests taking quite a lot of time
For simplicity, i have the following file named test.jsp: <script language=javascript> alert(a$b.replace(/\$/g,k)); </script> I
For example, suppose I have a batch file called 'test.cmd' and it simply contains:
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.