I am new here in the forum and I just start to work in a new web application on Visual studio 2013. I need to create an application that copy all the content from one Word Document to another. I had found this plugin that should make the job but I dont know how to put it in my code and make it work. I need to do it in a MVC application, so maybe I am not putting the code in the right place (now it is in the Model). Someone can help me telling me how to make it work? Please see the code that I have:
using Spire.Doc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace DocumentApplication.Models
{
public class HomeModel
{
public string Message { get; set; }
}
public class CopyDocument
{
Document sourceDoc = new Document("source.docx");
Document destinationDoc = new Document("target.docx");
foreach (Section sec in sourceDoc.Sections)
{
foreach (DocumentObject obj in sec.Body.ChildObjects)
{
destinationDoc.Sections[0].Body.ChildObjects.Add(obj.Clone());
}
}
destinationDoc.SaveToFile("target.docx");
System.Diagnostics.Process.Start("target.docx");
}
public class OpenDocument
{
Document document = new Document(@"C:\Users\daniel\Documents\ElAl-DRP.doc");
}
}
I cannot compile this because I have an error on the "foreach" line that says: "Invalid token 'foreach' in class' struct' or interface member declaration".
Please help me.
Thanks in advance