Beispiel #1
0
        /// <summary>
        /// Exports the Attachments folder contents (including subdirectories) in ZIP format.
        /// </summary>
        /// <returns>A <see cref="FileStreamResult"/> called 'attachments-export-{date}.zip'. This file is saved in the App_Data folder first.
        /// If an error occurs, the action adds the error message to the TempData 'ErrorMessage' item.</returns>
        public ActionResult ExportAttachments()
        {
            try
            {
                string zipFilename = string.Format("attachments-export-{0}.zip", DateTime.UtcNow.ToString("yyy-MM-dd-HHss"));
                _wikiExporter.ExportAttachments(zipFilename);

                string zipFullPath = Path.Combine(_wikiExporter.ExportFolder, zipFilename);
                return(File(zipFullPath, "application/zip", zipFilename));
            }
            catch (IOException e)
            {
                Log.Warn(e, "Unable to export attachments");
                TempData["ErrorMessage"] = string.Format(SiteStrings.SiteSettings_Tools_ExportAttachments_Error, e.Message);

                return(RedirectToAction("Index"));
            }
        }
Beispiel #2
0
        public void ExportAttachments_Should_Save_Zip_File_To_Export_Directory()
        {
            // Arrange
            string filename    = string.Format("attachments-{0}.zip", DateTime.Now.Ticks);
            string zipFullPath = Path.Combine(_wikiExporter.ExportFolder, filename);

            _applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Attachments");

            string filename1 = Path.Combine(_applicationSettings.AttachmentsFolder, "somefile1.txt");
            string filename2 = Path.Combine(_applicationSettings.AttachmentsFolder, "somefile2.txt");

            File.WriteAllText(filename1, "sample content");
            File.WriteAllText(filename2, "sample content");

            // Act
            _wikiExporter.ExportAttachments(filename);

            // Assert
            Assert.That(File.Exists(zipFullPath), Is.True);

            FileInfo file = new FileInfo(zipFullPath);

            Assert.That(file.Length, Is.GreaterThan(1));
        }