Пример #1
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     IsOK = false;
     ExportContent = ExportContent.None;
     ExportFormat = ExportFormat.None;
     ExportPath = "";
     Close();
 }
Пример #2
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     IsOK          = false;
     ExportContent = ExportContent.None;
     ExportFormat  = ExportFormat.None;
     ExportPath    = "";
     Close();
 }
Пример #3
0
        public ActionResult ExportContent(string ids, string fileName = "")
        {
            var view = string.Format(ViewsFolder, "Index");

            if (string.IsNullOrEmpty(ids))
            {
                ModelState.AddModelError("exportError", "please select at least one node to export");
                return(View(view));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    fileName  = string.IsNullOrWhiteSpace(fileName) ? "ExportedContent" : fileName;
                    fileName += ".zip";

                    var export = new ExportContent();

                    var xdoc  = export.SerialiseToXml(ids);
                    var files = export.GetListOfAssets(xdoc);

                    var ms    = new MemoryStream();
                    var msXml = new MemoryStream();

                    using (var zip = new ZipFile())
                    {
                        foreach (var f in files.Distinct())
                        {
                            // TODO for v6
                            if (FileHelpers.FileExists(f))
                            {
                                var fileAndParent = f.Replace(f.Split('/').Last(), string.Empty);
                                zip.AddFile(HostingEnvironment.MapPath(f), fileAndParent);
                            }
                        }

                        xdoc.Save(msXml);
                        msXml.Position = 0;
                        zip.AddEntry(Constants.ContentFileName, msXml);
                        zip.Save(ms);

                        ms.Position = 0;
                        return(File(ms, "application/zip", fileName));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("exportError", ex.Message);
                }
            }

            return(View(view));
        }
Пример #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (rbExportNew.Checked)
            {
                ExportContent = ExportContent.New;
            }
            if (rbExportCommon.Checked)
            {
                ExportContent = ExportContent.Common;
            }

            if (rbXML.Checked)
            {
                ExportFormat = ExportFormat.XML;
                ExportPath = tbXMLPath.Text;
            }
            if (rbText.Checked)
            {
                ExportFormat = ExportFormat.Text;
                ExportPath = tbTextPath.Text;
            }
            if (rbCopyFiles.Checked)
            {
                ExportFormat = ExportFormat.CopyFile;
                ExportPath = tbCopyFilePath.Text;
            }
            if (rbMoveFiles.Checked)
            {
                ExportFormat = ExportFormat.MoveFile;
                ExportPath = tbMoveFilePath.Text;
            }

            if (
                ExportContent != ExportContent.None
                && ExportFormat != ExportFormat.None
                && !string.IsNullOrEmpty(ExportPath)
                )
            {
                IsOK = true;
                Close();
            }
            else
            {
                MessageBox.Show("Export options has some matters. Please check and repair options.");
            }
        }
Пример #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (rbExportNew.Checked)
            {
                ExportContent = ExportContent.New;
            }
            if (rbExportCommon.Checked)
            {
                ExportContent = ExportContent.Common;
            }

            if (rbXML.Checked)
            {
                ExportFormat = ExportFormat.XML;
                ExportPath   = tbXMLPath.Text;
            }
            if (rbText.Checked)
            {
                ExportFormat = ExportFormat.Text;
                ExportPath   = tbTextPath.Text;
            }
            if (rbCopyFiles.Checked)
            {
                ExportFormat = ExportFormat.CopyFile;
                ExportPath   = tbCopyFilePath.Text;
            }
            if (rbMoveFiles.Checked)
            {
                ExportFormat = ExportFormat.MoveFile;
                ExportPath   = tbMoveFilePath.Text;
            }

            if (
                ExportContent != ExportContent.None &&
                ExportFormat != ExportFormat.None &&
                !string.IsNullOrEmpty(ExportPath)
                )
            {
                IsOK = true;
                Close();
            }
            else
            {
                MessageBox.Show("Export options has some matters. Please check and repair options.");
            }
        }
Пример #6
0
        public static FileInfo NormalExport(string FileName, ExportContent ImplementExportContent)
        {
            GC.Collect();
            string tempdirectory = ConfigurationManager.AppSettings["EmployeeExportLocation"];

            if (!Directory.Exists(tempdirectory))
            {
                Directory.CreateDirectory(tempdirectory);
            }
            string      templocation = tempdirectory + "\\" + FileName;
            Application excel        = new Application();
            _Workbook   xBk          = excel.Workbooks.Add(Type.Missing);
            _Worksheet  xSt          = (_Worksheet)xBk.ActiveSheet;

            try
            {
                if (ImplementExportContent != null)
                {
                    ImplementExportContent(excel);
                }
                object nothing    = Type.Missing;
                object fileFormat = XlFileFormat.xlExcel8;
                object file1      = templocation;
                if (File.Exists(file1.ToString()))
                {
                    File.Delete(file1.ToString());
                }
                xBk.SaveAs(file1, fileFormat, nothing, nothing, nothing, nothing, XlSaveAsAccessMode.xlNoChange, nothing,
                           nothing, nothing, nothing, nothing);
            }
            finally
            {
                xBk.Close(false, null, null);
                excel.Quit();
                Marshal.ReleaseComObject(xBk);
                Marshal.ReleaseComObject(excel);
                Marshal.ReleaseComObject(xSt);
                GC.Collect();
            }
            FileInfo file = new FileInfo(templocation);

            return(file);
        }
        public ActionResult ExportContent(string ids, string fileName = "")
        {
            var view = string.Format(ViewsFolder, "Index");

            if (string.IsNullOrEmpty(ids))
            {
                ModelState.AddModelError("exportError", "please select at least one node to export");
                return View(view);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    fileName = string.IsNullOrWhiteSpace(fileName) ? "ExportedContent" : fileName;
                    fileName += ".zip";

                    var export = new ExportContent();

                    var xdoc = export.SerialiseToXml(ids);
                    var files = export.GetListOfAssets(xdoc);

                    var ms = new MemoryStream();
                    var msXml = new MemoryStream();

                    using (var zip = new ZipFile())
                    {
                        foreach (var f in files.Distinct())
                        {
                            // TODO for v6
                            if (FileHelpers.FileExists(f))
                            {
                                var fileAndParent = f.Replace(f.Split('/').Last(), string.Empty);
                                zip.AddFile(HostingEnvironment.MapPath(f), fileAndParent);
                            }
                        }

                        xdoc.Save(msXml);
                        msXml.Position = 0;
                        zip.AddEntry(Constants.ContentFileName, msXml);
                        zip.Save(ms);

                        ms.Position = 0;
                        return File(ms, "application/zip", fileName);
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("exportError", ex.Message);
                }
            }

            return View(view);
        }
Пример #8
0
 internal ExportDirectory(ExportContent exportContent, IMAGE_EXPORT_DIRECTORY exportDir, StreamLocation streamLoc)
 {
     content = exportContent;
     directory = exportDir;
     location = streamLoc;
 }