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:GetHTMLBodyTagContentsWithExternalResources //ExStart:GetHTMLExternalCSSContents /// <summary> /// Get HTML document external CSS content. /// </summary> public static void GetHTMLExternalCSSContents() { // Obtain document stream Stream sourceStream = File.Open(Path.Combine(Common.sourcePath, Common.sourceFile), FileMode.Open, FileAccess.Read); using (InputHtmlDocument htmlDoc = EditorHandler.ToHtml(sourceStream)) { // Obtain CSS content string cssContent = htmlDoc.GetCssContent(); Console.WriteLine(cssContent); } // close stream object to release file for other methods. sourceStream.Close(); }
//ExEnd:GetHTMLExternalCSSContents //ExStart:GetHTMLExternalCSSContentsWithExternalResources /// <summary> /// Get HTML document external CSS content with external resource prefix. /// </summary> public static void GetHTMLExternalCSSContentsWithExternalResources() { // 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 CSS content string cssContent = htmlDoc.GetCssContent(externalResourcePrefix); Console.WriteLine(cssContent); } // close stream object to release file for other methods. sourceStream.Close(); }