public ActionResult XMLMapping(string Button)
        {
            if (Button == null)
            {
                return(View());
            }

            #region XML Mapping

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);
            docIOxmlPart.Load(ResolveApplicationDataPath("Employees.xml", "Data\\DocIO"));

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);
            #endregion

            return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
        }
Пример #2
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly    = Assembly.GetExecutingAssembly();
            Stream   inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Employees.xml");

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);
            MemoryStream stream = new MemoryStream();

            document.Save(stream, FormatType.Word2013);
            document.Close();

            if (stream != null)
            {
                SaveiOS iOSSave = new SaveiOS();
                iOSSave.Save("XMLMapping.docx", "application/msword", stream);
            }
        }
        // GET: /<controller>/
        public IActionResult XMLMapping(string Group)
        {
            if (Group == null)
            {
                return(View());
            }
            string basePath = _hostingEnvironment.WebRootPath;
            // Load Template document stream.
            FileStream inputStream = new FileStream(basePath + @"/DocIO/Employees.xml", FileMode.Open, FileAccess.Read);

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";

            MemoryStream ms = new MemoryStream();

            document.Save(ms, type);
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Пример #4
0
        /// <summary>
        /// Button click event for XMLMapping.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void OnButtonClicked(object sender, EventArgs e)
        {
            // Load Template document stream.
            Stream inputStream = typeof(XMLMapping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.DocIO.Samples.Templates.Employees.xml");

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

            MemoryStream stream = new MemoryStream();

            document.Save(stream, FormatType.Docx);
            document.Close();

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                DependencyService.Get <ISaveWindowsPhone>()
                .Save("XMLMapping.docx", "application/msword", stream);
            }
            else
            {
                DependencyService.Get <ISave>().Save("XMLMapping.docx", "application/msword", stream);
            }
        }
Пример #5
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Get XML file path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\Data\DocIO\";
                // Create a new document.
                WordDocument document = new WordDocument();

                //Add a section & a paragraph in the empty document.
                document.EnsureMinimal();

                //Loads XML file into the customXML part of the Word document.
                CustomXMLPart docIOxmlPart = new CustomXMLPart(document);
                docIOxmlPart.Load(System.IO.Path.Combine(dataPath, "Employees.xml"));

                //Insert content controls and maps Employees details to it.
                InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Docx);
                document.Close();

                //Message box confirmation to view the created document.
                if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.docx");
#endif
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Пример #6
0
        /// <summary>
        /// Button click event for XMLMapping.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event args</param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // Load Template document stream.
            Stream inputStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Employees.xml");

            // Create a new document.
            WordDocument document = new WordDocument();

            //Add a section & a paragraph in the empty document.
            document.EnsureMinimal();

            //Loads XML file into the customXML part of the Word document.
            CustomXMLPart docIOxmlPart = new CustomXMLPart(document);

            docIOxmlPart.Load(inputStream);

            //Insert content controls and maps Employees details to it.
            InsertAndMapEmployees(document, "EmployeesList", docIOxmlPart);

            Save(document);
        }