Add \e Switch to INDEX Field to Define Separator for Index Entry (XE Field) & Page Number or Cross References C# .NET | \z switch

@maik2,

The archive you shared earlier contains “current” and “expected” documents and a project which unfortunately does not give any idea how you produce the documents in question. We explored the “current” state document and discovered that the INDEX field’s parent paragraph does not contain a correct right aligned tab stop.

We have processed the “current” document by applying these changes to existing code:

  1. remove the original field
  2. use Dashed tab stop
  3. update fields before save.

C# code:

Document doc = new Document("current.docx");

// Removes the existing INDEX field.
foreach (Field field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldIndex))
    field.Remove();

var builder = new DocumentBuilder(doc);

builder.InsertField("INDEX \\e \"\t\" \\z \"1033\"");

var tabStop = new TabStop();
tabStop.Alignment = TabAlignment.Right;
tabStop.Leader = TabLeader.Dashes;    // Or any other leader type.

builder.ParagraphFormat.TabStops.Add(tabStop);
builder.Writeln();

doc.UpdateFields();

doc.Save("Test21131 Out.docx");

The output document is attached: Test21131 Out.zip (8.1 KB)

Regarding the multiple indexes, yes it’s possible, you should consider the \f switch (entry type) (there are a lot of tutorials out there like: Placing More Than One Index in a Document