how to transfer information from (.docx format) to (.docm format) using .Net-Core?

Viewed 97
1 Answers
    public void ConvertDOCXtoDOCM(string fileName)
    {
        bool fileChanged = false;



        using (WordprocessingDocument document =
    WordprocessingDocument.Open(fileName, true))
        {
           
            document.ChangeDocumentType(
                WordprocessingDocumentType.MacroEnabledDocument);

            // Track that the document has been changed.
            fileChanged = true;
        }

        // If anything goes wrong in this file handling,
        // the code will raise an exception back to the caller.
        if (fileChanged)
        {
            // Create the new .docx filename.
            var newFileName = Path.ChangeExtension(fileName, ".docm");

            // If it already exists, it will be deleted!
            if (File.Exists(newFileName))
            {
                File.Delete(newFileName);
            }

            // Rename the file.
            File.Move(fileName, newFileName);
        }

    }
Related