We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert Text Files (.bat- .ini. txt) into Word Document


Im currently playing about with a aspose in Demo Mode which I must say is great, but before I recommend purchasing this tour company I want to be 100% it will do what I need.

currently I have Word document that using VBA code basically does the following…

  1. Search and replace < Tags > within the Document

  2. Finds Bookmarks < bookmarkFilename > and inserts a file into the this bookmark
    In VBA, its just a simple couple of lines…

ActiveDocument.Bookmarks("BookMarkName).Range.Text = _
CreateObject("scripting.filesystemobject").opentextfile(DIRPath + "\filename.txt").ReadAll()

Is there something similar within Aspose ?

Im currently trying to Migrate this VBA code to VB via Visual Studio which is working fine for the Search and replace.

But I’m struggling to find an relevant documentation on how to import plain text files (.bat, .txt., .ini) into the Bookmarks via aspose.

any help or guidance would be much appreciated

Hi there,

Thanks for your inquiry.


  1. Search and replace < Tags > within the Document*

You can achieve this by using Find and Replace feature of Aspose.Words. Please read the detail from here:


  1. Finds Bookmarks < bookmarkFilename > and inserts a file into the this bookmark*

Please use following code example to achieve your requirements. Hope this helps you.

// Load bat, ini, txt document into Aspose.Words DOM
LoadOptions options = new LoadOptions();
options.LoadFormat = LoadFormat.Text;
Document txtDoc = new Document(MyDir + "in.bat", options);
// Load Word document 
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Move cursor to the bookmark
// Insert .bat, .ini, txt document at the position of bookmark
builder.InsertDocument(txtDoc, ImportFormatMode.KeepSourceFormatting);
doc.Save(MyDir + "Out.docx");

I suggest you please read following documentation links for your kind reference.
2) Load your document