public ActionResult EditExistent(string fullPath)
        {
            string storageFolderPath         = ((InitData)Session["initData"]).FullStoragePath;
            string preparedFolderName        = Repository.PrepareFilename(fullPath);
            string fullStorageItemFolderPath = System.IO.Path.Combine(storageFolderPath, preparedFolderName);

            Repository.ClearOrCreate(fullStorageItemFolderPath);
            string originalFolderPath = System.IO.Path.Combine(fullStorageItemFolderPath, Constants.OriginalFolderName);

            Repository.ClearOrCreate(originalFolderPath);

            string resourceRequestPrefix = string.Format("GetResource?htmlDocumentFolderName={0}&resourceFilename=", preparedFolderName);

            string bodyContent;

            using (System.IO.FileStream inputDoc = System.IO.File.OpenRead(fullPath))
                using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(inputDoc))
                {
                    string externalResourcePrefix = "GetResource?htmlDocumentFolderName=" + preparedFolderName + "&resourceFilename=";
                    bodyContent = htmlDoc.GetBodyContent(externalResourcePrefix);
                    string resultantHtmlDocPath = System.IO.Path.Combine(originalFolderPath, Constants.HtmlFilename);
                    htmlDoc.Save(resultantHtmlDocPath);
                    string cssText            = htmlDoc.GetCssContent(resourceRequestPrefix);
                    string resourceFolderPath = System.IO.Path.Combine(originalFolderPath, Constants.HtmlResourceFolderName);
                    string cssFilePath        = System.IO.Path.Combine(resourceFolderPath, Constants.CssFilename);
                    System.IO.File.WriteAllText(cssFilePath, cssText);
                }

            CultureInfo[]         cultures  = CultureInfo.GetCultures(CultureTypes.AllCultures);
            List <SelectListItem> listItems = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Selected = true,
                    Text     = "(default)",
                    Value    = 0.ToString()
                }
            };

            foreach (CultureInfo culture in cultures)
            {
                listItems.Add(new SelectListItem()
                {
                    Selected = false,
                    Text     = culture.EnglishName,
                    Value    = culture.LCID.ToString(CultureInfo.InvariantCulture)
                });
            }

            EditModel em = new EditModel()
            {
                EditableDocumentName = System.IO.Path.GetFileName(fullPath),
                CssRelativePath      = resourceRequestPrefix + Constants.CssFilename,
                HtmlContent          = bodyContent,
                Locales       = listItems,
                IsNewDocument = false
            };

            return(View("Edit", em));
        }
        //ExEnd:SaveToWordsDocument

        //ExStart:SaveToWordsDocumentWithOptions
        /// <summary>
        /// Save to Words document with options.
        /// </summary>
        public static void SaveToWordsDocumentWithOptions()
        {
            // Obtain document stream
            Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read);

            using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
            {
                // Obtain HTML document content
                string htmlContent = htmlDoc.GetContent();

                using (OutputHtmlDocument editedHtmlDoc = OutputHtmlDocument.FromMarkup(htmlContent, Path.Combine(Common.sourcePath, Common.resultResourcesFolder)))
                {
                    using (System.IO.FileStream outputStream = System.IO.File.Create(Path.Combine(Common.resultPath, Common.resultFile)))
                    {
                        WordsSaveOptions saveOptions = new WordsSaveOptions(WordFormats.Docx, Common.sourceFilePassword);
                        saveOptions.Locale        = CultureInfo.GetCultureInfo(1);
                        saveOptions.LocaleBi      = CultureInfo.GetCultureInfo(1);
                        saveOptions.LocaleFarEast = CultureInfo.GetCultureInfo(2);
                        EditorHandler.ToDocument(editedHtmlDoc, outputStream, saveOptions);
                    }
                }
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }
        private static List <Document> GetDefaultDocuments()
        {
            List <Document> Documents = new List <Document>();

            string SampleHTMLDirectory = HostingEnvironment.MapPath("/App_Data/Samples");

            string[] HTMLFiles = Directory.GetFiles(SampleHTMLDirectory);
            int      SrNo      = 0;

            foreach (string SampleHTMlFile in HTMLFiles)
            {
                if (Path.GetExtension(SampleHTMlFile) == ".html")
                {
                    string Name = Path.GetFileNameWithoutExtension(SampleHTMlFile);
                    string HTML = File.ReadAllText(SampleHTMlFile);
                    int    size = HTML.Length;

                    Document SampleDocument = new Document()
                    {
                        SrNo = SrNo, Name = Name, HTML = HTML, Size = size, LastUpdated = "default"
                    };
                    Documents.Add(SampleDocument);
                }
                if (Path.GetExtension(SampleHTMlFile) == ".doc" || Path.GetExtension(SampleHTMlFile) == ".docx")
                {
                    string Name = Path.GetFileNameWithoutExtension(SampleHTMlFile);
                    string HTML = "";
                    // Obtain document stream
                    Stream sourceStream = File.Open(SampleHTMlFile, FileMode.Open, FileAccess.Read);
                    using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
                    {
                        // Obtain HTML document content
                        HTML = htmlDoc.GetContent();
                    }
                    // close stream object to release file for other methods.
                    sourceStream.Close();


                    //string Name = Path.GetFileNameWithoutExtension(SampleHTMlFile);
                    //string HTML = File.ReadAllText(SampleHTMlFile);
                    int size = HTML.Length;

                    Document SampleDocument = new Document()
                    {
                        SrNo = SrNo, Name = Name, HTML = HTML, Size = size, LastUpdated = "default"
                    };
                    Documents.Add(SampleDocument);
                }
                SrNo++;
            }
            return(Documents);
        }
Ejemplo n.º 4
0
        //ExEnd:GetHTMLExternalCSSContentsWithExternalResources

        //ExStart:SaveHTMLDocument
        /// <summary>
        /// Save HTML document.
        /// </summary>
        public static void SaveHTMLDocument()
        {
            // Obtain document stream
            Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read);

            using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
            {
                htmlDoc.Save(Path.Combine(Common.resultPath, Common.resultFile));
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }
Ejemplo n.º 5
0
        //ExEnd:SaveHTMLDocumentWithResourcesFolder

        //ExStart:TraverseHTMLResourcesAndCSS
        /// <summary>
        /// Traverse HTML document and save resources by specifying resource folder name.
        /// </summary>
        public static void TraverseHTMLResourcesAndCSS()
        {
            // Obtain document stream
            Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read);

            using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
            {
                foreach (IFontResource fontResource in htmlDoc.FontResources)
                {
                    Console.WriteLine(fontResource.FilenameWithExtension);
                    Console.WriteLine(fontResource.Name);
                    Console.WriteLine(fontResource.ByteContent);
                    Console.WriteLine(fontResource.TextContent);

                    string pathToResource = string.Format(Path.Combine(Common.resultPath, Common.resultResourcesFolder) + "\\{0}", fontResource.FilenameWithExtension);
                    fontResource.Save(pathToResource);
                }

                foreach (RasterImageResourceBase imageResource in htmlDoc.ImageResources)
                {
                    Console.WriteLine(imageResource.FilenameWithExtension);
                    Console.WriteLine(imageResource.ByteContent);
                    Console.WriteLine(imageResource.Name);
                    Console.WriteLine(imageResource.TextContent);
                    Console.WriteLine(imageResource.LinearDimensions.Height);
                    Console.WriteLine(imageResource.LinearDimensions.Width);
                    Console.WriteLine(imageResource.LinearDimensions.IsSquare);

                    string pathToResource = string.Format(Path.Combine(Common.resultPath, Common.resultResourcesFolder) + "\\{0}", imageResource.FilenameWithExtension);
                    imageResource.Save(pathToResource);
                }

                CssText css = htmlDoc.Css;
                Console.WriteLine(css.FilenameWithExtension);
                Console.WriteLine(css.ByteContent);
                Console.WriteLine(css.Name);
                Console.WriteLine(css.TextContent);
                Console.WriteLine(css.Encoding);

                string pathToCss = string.Format(Path.Combine(Common.resultPath, Common.resultResourcesFolder) + "\\{0}", css.FilenameWithExtension);
                css.Save(pathToCss);

                // saving output html file.
                htmlDoc.Save(Path.Combine(Common.resultPath, Common.resultFile), Path.Combine(Common.resultPath, Common.resultResourcesFolder));
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }
Ejemplo n.º 6
0
        //ExStart:GetHTMLContents
        /// <summary>
        /// Get HTML document content.
        /// </summary>
        public static void GetHTMLContents()
        {
            // Obtain document stream
            Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read);

            using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
            {
                // Obtain HTML document content
                string bodyContent = htmlDoc.GetContent();
                Console.WriteLine(bodyContent);
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }
Ejemplo n.º 7
0
        //ExEnd:GetHTMLContents

        //ExStart:GetHTMLContentsWithExternalResources
        /// <summary>
        /// Get HTML document content with external resource prefix.
        /// </summary>
        public static void GetHTMLContentsWithExternalResources()
        {
            // Obtain document stream
            Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read);

            using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream))
            {
                string externalResourcePrefix = "GetResource?htmlDocumentFolderName=" + Common.sourceResourcesFolder + "&resourceFilename=Picture 3.png";

                // Obtain HTML document content
                string bodyContent = htmlDoc.GetContent(externalResourcePrefix);
                Console.WriteLine(bodyContent);
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }
Ejemplo n.º 8
0
        private LoadDocumentEntity LoadDocument(string guid, string password)
        {
            try
            {
                dynamic options = null;
                //GroupDocs.Editor cannot detect text-based Cells documents formats (like CSV) automatically
                if (guid.EndsWith("csv", StringComparison.OrdinalIgnoreCase))
                {
                    options = new SpreadsheetToHtmlOptions();
                }
                else
                {
                    options = EditorHandler.DetectOptionsFromExtension(guid);
                }

                if (options is SpreadsheetToHtmlOptions)
                {
                    options.TextOptions = options.TextLoadOptions(",");
                }
                else
                {
                    options.Password = password;
                }
                string bodyContent;

                using (System.IO.FileStream inputDoc = System.IO.File.OpenRead(guid))

                    using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(inputDoc, options))
                    {
                        bodyContent = htmlDoc.GetEmbeddedHtml();
                    }
                LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();
                loadDocumentEntity.SetGuid(System.IO.Path.GetFileName(guid));
                PageDescriptionEntity page = new PageDescriptionEntity();
                page.SetData(bodyContent);
                loadDocumentEntity.SetPages(page);
                return(loadDocumentEntity);
            }
            catch
            {
                throw;
            }
        }