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));
        }
Ejemplo n.º 2
0
        //ExEnd:GetHTMLContentsWithEmbeddedResources

        //ExStart:GetHTMLBodyTagContents
        /// <summary>
        /// Get HTML document BODY tag content.
        /// </summary>
        public static void GetHTMLBodyTagContents()
        {
            // 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 body content
                string bodyContent = htmlDoc.GetBodyContent();

                Console.WriteLine(bodyContent);
            }

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

        //ExStart:GetHTMLBodyTagContentsWithExternalResources
        /// <summary>
        /// Get HTML document BODY tag content with external resource prefix.
        /// </summary>
        public static void GetHTMLBodyTagContentsWithExternalResources()
        {
            // 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 body content
                string bodyContent = htmlDoc.GetBodyContent(externalResourcePrefix);

                Console.WriteLine(bodyContent);
            }

            // close stream object to release file for other methods.
            sourceStream.Close();
        }