I am breaking my head for a long time now and couldn't find any relevant info here or google. I am developing in ASP.NET Core 1.0 so I use the OpenXml lib. I have the following code based on samples and tutorials:
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace AutoDocumentation.Dll
{
public class WriteToFile
{
// Path of the word doc.
private const string wordFilePath = @"C:\file.docx";
static WordprocessingDocument wpd = WordprocessingDocument.Create(wordFilePath, WordprocessingDocumentType.Document);
MainDocumentPart mdp = wpd.MainDocumentPart;
mdp.Document = new Document();
}
}
The problem is that mdp.Document line throws the error
"The name 'mdp' does not exist in the current context."
which is obviously not true. Can you suggest a turn around or what am I doing wrong?
You can only declare and initialize fields in the class body, this line should be placed inside a constructor.