コード例 #1
0
        public async Task <IActionResult> Create(LoadFormatViewModel viewModel)
        {
            FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes));

            if (ModelState.IsValid)
            {
                LoadFormat loadFormat = new LoadFormat();
                loadFormat           = viewModel.LoadFormat;
                loadFormat.ID        = Guid.NewGuid();
                loadFormat.ProductID = viewModel.ProductID;
                _context.Add(loadFormat);
                await _context.SaveChangesAsync();

                //  Populate Format Types

                var loadFormatId = loadFormat.ID;
                PopulateFormatTypes(loadFormatId);
                return(RedirectToAction("Index", new { productId = viewModel.ProductID }));
            }
            var list = (from value in values
                        select new SelectListItem()
            {
                Value = ((int)value).ToString(),
                Text = value.ToString()
            }).ToList();

            viewModel.FileTypeList = new SelectList(list, "Value", "Text");
            return(View(viewModel));
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_PresentationOpening();

            LoadFormat format = PresentationFactory.Instance.GetPresentationInfo(dataDir + "HelloWorld.pptx").LoadFormat;
            // It will return "LoadFormat.Unknown" if the file is other than presentation formats
        }
コード例 #3
0
        public void DetectFileFormat_SaveFormatToLoadFormat()
        {
            //ExStart
            //ExFor:FileFormatUtil.SaveFormatToLoadFormat(SaveFormat)
            //ExSummary:Shows how to use the FileFormatUtil class and to convert a SaveFormat enumeration into the corresponding LoadFormat enumeration.
            // Define the SaveFormat enumeration to convert.
            SaveFormat saveFormat = SaveFormat.Html;
            // Convert the SaveFormat enumeration to LoadFormat enumeration.
            LoadFormat loadFormat = FileFormatUtil.SaveFormatToLoadFormat(saveFormat);

            Console.WriteLine("The converted LoadFormat is: " + FileFormatUtil.LoadFormatToExtension(loadFormat));
            //ExEnd

            Assert.AreEqual(".html", FileFormatUtil.SaveFormatToExtension(saveFormat));
            Assert.AreEqual(".html", FileFormatUtil.LoadFormatToExtension(loadFormat));
        }
コード例 #4
0
        public static byte[] ConvertToPdf(
            byte[] file,
            LoadFormat loadFormat = LoadFormat.Auto,
            SaveFormat saveFormat = SaveFormat.Pdf
            )
        {
            try {
                var stream = new MemoryStream(file);
                var doc    = new Document(stream, null, loadFormat, null);

                using (var streamForDoc = new MemoryStream()) {
                    doc.Save(streamForDoc, saveFormat);
                    return(streamForDoc.ToArray());
                }
            } catch (Exception) {
                return(null);
            }
        }
コード例 #5
0
        public void DetectFileFormat_EnumConversions()
        {
            //ExStart
            //ExFor:FileFormatUtil.DetectFileFormat(Stream)
            //ExFor:FileFormatUtil.LoadFormatToExtension(LoadFormat)
            //ExFor:FileFormatUtil.ExtensionToSaveFormat(String)
            //ExFor:FileFormatUtil.SaveFormatToExtension(SaveFormat)
            //ExFor:FileFormatUtil.LoadFormatToSaveFormat(LoadFormat)
            //ExFor:Document.OriginalFileName
            //ExFor:FileFormatInfo.LoadFormat
            //ExSummary:Shows how to use the FileFormatUtil methods to detect the format of a document without any extension and save it with the correct file extension.
            // Load the document without a file extension into a stream and use the DetectFileFormat method to detect it's format.
            // These are both times where you might need extract the file format as it's not visible
            FileStream
                docStream = File.OpenRead(
                MyDir + "Document.FileWithoutExtension");     // The file format of this document is actually ".doc"
            FileFormatInfo info = FileFormatUtil.DetectFileFormat(docStream);

            // Retrieve the LoadFormat of the document.
            LoadFormat loadFormat = info.LoadFormat;

            // Let's show the different methods of converting LoadFormat enumerations to SaveFormat enumerations.
            //
            // Method #1
            // Convert the LoadFormat to a String first for working with. The String will include the leading dot in front of the extension.
            String fileExtension = FileFormatUtil.LoadFormatToExtension(loadFormat);
            // Now convert this extension into the corresponding SaveFormat enumeration
            SaveFormat saveFormat = FileFormatUtil.ExtensionToSaveFormat(fileExtension);

            // Method #2
            // Convert the LoadFormat enumeration directly to the SaveFormat enumeration.
            saveFormat = FileFormatUtil.LoadFormatToSaveFormat(loadFormat);

            // Load a document from the stream.
            Document doc = new Document(docStream);

            // Save the document with the original file name, " Out" and the document's file extension.
            doc.Save(
                ArtifactsDir + "Document.WithFileExtension" + FileFormatUtil.SaveFormatToExtension(saveFormat));
            //ExEnd

            Assert.AreEqual(".doc", FileFormatUtil.SaveFormatToExtension(saveFormat));
        }
        public static void Main()
        {
            // Initialize Text File's LoadFormat
            LoadFormat oLoadFormat = LoadFormat.CSV;

            // Initialize Text File's Load options
            TxtLoadOptions oTxtLoadOptions = new TxtLoadOptions(oLoadFormat);

            // Specify the separatot character
            oTxtLoadOptions.Separator = Convert.ToChar(",");

            // Specify the encoding scheme
            oTxtLoadOptions.Encoding = System.Text.Encoding.UTF8;

            // Set the flag to true for converting datetime data
            oTxtLoadOptions.ConvertDateTimeData = true;

            // Set the preferred parsers
            oTxtLoadOptions.PreferredParsers = new ICustomParser[] { new TextParser(), new DateParser() };

            // Initialize the workbook object by passing CSV file and text load options
            Workbook oExcelWorkBook = new Aspose.Cells.Workbook(sourceDir + "samplePreferredParser.csv", oTxtLoadOptions);

            // Get the first cell
            Cell oCell = oExcelWorkBook.Worksheets[0].Cells["A1"];

            // Display type of value
            Console.WriteLine("A1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);

            // Get the second cell
            oCell = oExcelWorkBook.Worksheets[0].Cells["B1"];

            // Display type of value
            Console.WriteLine("B1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);

            // Save the workbook to disc
            oExcelWorkBook.Save(outputDir + "outputsamplePreferredParser.xlsx");

            Console.WriteLine("OpeningCSVFilesWithPreferredParser executed successfully.\r\n");
        }
コード例 #7
0
        public void SaveToDetectedFileFormat()
        {
            //ExStart
            //ExFor:FileFormatUtil.DetectFileFormat(Stream)
            //ExFor:FileFormatUtil.LoadFormatToExtension(LoadFormat)
            //ExFor:FileFormatUtil.ExtensionToSaveFormat(String)
            //ExFor:FileFormatUtil.SaveFormatToExtension(SaveFormat)
            //ExFor:FileFormatUtil.LoadFormatToSaveFormat(LoadFormat)
            //ExFor:Document.OriginalFileName
            //ExFor:FileFormatInfo.LoadFormat
            //ExFor:LoadFormat
            //ExSummary:Shows how to use the FileFormatUtil methods to detect the format of a document.
            // Load a document from a file that is missing a file extension, and then detect its file format.
            using (FileStream docStream = File.OpenRead(MyDir + "Word document with missing file extension"))
            {
                FileFormatInfo info       = FileFormatUtil.DetectFileFormat(docStream);
                LoadFormat     loadFormat = info.LoadFormat;

                Assert.AreEqual(LoadFormat.Doc, loadFormat);

                // Below are two methods of converting a LoadFormat to its corresponding SaveFormat.
                // 1 -  Get the file extension string for the LoadFormat, then get the corresponding SaveFormat from that string:
                string     fileExtension = FileFormatUtil.LoadFormatToExtension(loadFormat);
                SaveFormat saveFormat    = FileFormatUtil.ExtensionToSaveFormat(fileExtension);

                // 2 -  Convert the LoadFormat directly to its SaveFormat:
                saveFormat = FileFormatUtil.LoadFormatToSaveFormat(loadFormat);

                // Load a document from the stream, and then save it to the automatically detected file extension.
                Document doc = new Document(docStream);

                Assert.AreEqual(".doc", FileFormatUtil.SaveFormatToExtension(saveFormat));

                doc.Save(ArtifactsDir + "File.SaveToDetectedFileFormat" + FileFormatUtil.SaveFormatToExtension(saveFormat));
            }
            //ExEnd
        }
コード例 #8
0
        public async Task <IActionResult> Edit(LoadFormatViewModel viewModel)
        {
            FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes));

            var list = (from value in values
                        select new SelectListItem()
            {
                Value = ((int)value).ToString(),
                Text = value.ToString()
            }).ToList();

            if (ModelState.IsValid)
            {
                LoadFormat loadFormat = new LoadFormat();
                loadFormat = viewModel.LoadFormat;
                try
                {
                    _context.Update(loadFormat);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoadFormatExists(loadFormat.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", new { productId = loadFormat.ProductID }));
            }
            viewModel.FileTypeList = new SelectList(list, "Value", "Text", viewModel.LoadFormat.UploadFileType);
            return(View(viewModel));
        }
コード例 #9
0
		public virtual void Open(Stream stream, LoadFormat format)
		{
			//Load binary
			if (format == LoadFormat.Binary)
			{
				BinaryFormatter formatter = new BinaryFormatter();
				LoadDiagram(stream,formatter);
			}
				//Load xml
			else if (format == LoadFormat.Xml)
			{
				SoapFormatter formatter = new SoapFormatter();
				LoadDiagram(stream,formatter);
			}
		}
コード例 #10
0
		public virtual void Open(string path, LoadFormat format)
		{
			Stream stream = new FileStream(path, FileMode.Open);

			//Load binary
			if (format == LoadFormat.Binary)
			{
				BinaryFormatter formatter = new BinaryFormatter();
				LoadDiagram(stream, formatter);
			}
			//Load xml
			else if (format == LoadFormat.Xml)
			{
				SoapFormatter formatter = new SoapFormatter();
				LoadDiagram(stream, formatter);
			}

			stream.Close();
		}
コード例 #11
0
ファイル: InvoicingService.cs プロジェクト: Dnigor/mycnew
        WorkbookDesigner GetWorkbookDesigner(string fileName, LoadFormat format)
        {
            using (var designerFileStream = GetLocalizedTemplate(fileName))
                if (designerFileStream != null)
                    return new WorkbookDesigner
                    {
                        Workbook = new Workbook(designerFileStream, new LoadOptions(format))
                    };

            return null;
        }