I would like to insert an image, then a new line and then another image. The process has to be repeated until all the images are inserted. This is my code as of now which inserts images, but not blank lines
using System.IO;
using Word = Microsoft.Office.Interop.Word;
namespace Snapper
{
class WordDocumentGenerator
{
public void CreateWordDocument(string fileName)
{
string originalPath = Directory.GetCurrentDirectory();
string path = originalPath;
path += @"\snapshots";
object oMissing = System.Reflection.Missing.Value;
//Create a new Word Application
Word._Application wordApp = new Word.Application();
wordApp.Visible = false;
try
{
//Create a new blank document
Word._Document doc = wordApp.Documents.Add(ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
string[] images = Directory.GetFiles(path);
//Create a range
object myTrue = true;
object myFalse = false;
object endOfDoc = "\\endofdoc";
object myRange;
foreach (var image in images)
{
myRange = doc.Bookmarks.get_Item(ref endOfDoc).Range;
//Add images to the document
doc.InlineShapes.AddPicture(image, ref myFalse, ref myTrue, ref myRange);
//Add a blank line
//doc.Content.Text = "\n";
}
path = originalPath;
path += @"\documents";
DirectoryInfo docDir = new DirectoryInfo(path);
if (!docDir.Exists)
{
docDir.Create();
}
object savePath = path + @"\" + fileName + ".doc";
doc.SaveAs(ref savePath,
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
);
doc.Save();
}
finally
{
wordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
}
}
}
}
I need some help in doing it.