Hi,
I want to get only the header and footer string in word 2003 using c#, kindly help me out.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Bharath PeggemRank #3,303 · 435 reputationPosted Nov 4, 2015, 6:45 PM EST
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false; //to avoid displaying the Word Application
object strDocName = @"d:\test.doc";
object objBool = false;
object objNull = System.Reflection.Missing.Value;
Document oMyDoc = oWord.Documents.Open(ref strDocName, ref objBool, ref objBool, ref objBool, ref objNull,
ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull);
object objReference = System.Reflection.Missing.Value;
object objFoot = "this is footer";
object objStart = 0;
object objEnd = oMyDoc.Words.Count;
if (oMyDoc.Sections.Count > 0)
{
oMyDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "My Header";
oMyDoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "My Footer";
}