HTMLDocument.Save

Save(Url)

Saves the document to a local file specified by url. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as output_file_name + “_files”.

public void Save(Url url)
ParameterTypeDescription
urlUrlLocal URL to output file.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified url is not a valid local file URL.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(Url) Method

It is necessary to specify a full Url path - ‘outputFilePath’ for HTML document saving. The Url(url) constructor creates an instance of the Url class with the specified url. Then you should pass the instance to the Save(Url) method. The document will be saved to the local file specified by url. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as output_file_name + “_files”.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
        
	var outputFilePath = Path.Combine(outputHtmlPath, "result.html");
	document.Save(new Url(outputFilePath));
}

*inputHtmlPath - user input html file.

*outputHtmlPath - user output folder path.

See Also


Save(ResourceHandler)

Saves the document content and resources using the ResourceHandler.

public void Save(ResourceHandler resourceHandler)
ParameterTypeDescription
resourceHandlerResourceHandlerThe resource handler ResourceHandler.

See Also


Save(string)

Saves the document to a local file specified by path. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(string path)
ParameterTypeDescription
pathStringLocal file system path to output file.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified path is not a valid local file path.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(String) method takes as a parameter a local file system path to an output file and saves an HTML document to the local file specified by path. All resources used in the document will be saved into an adjacent folder.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
...
 using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (outputHtmlPath == null)
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.html");
	document.Save(outputFilePath);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output directory path.

See Also


Save(string, HTMLSaveFormat)

Saves the document to a local file specified by path. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as output_file_name + “_files”.

public void Save(string path, HTMLSaveFormat saveFormat)
ParameterTypeDescription
pathStringLocal file path to output file.
saveFormatHTMLSaveFormatFormat in which document is saved.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified path is not a valid local file path.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(String, HTMLSaveFormat) Method

Save(String, HTMLSaveFormat) method takes as parameters a local file system path to output file and saveFormat. The HTMLSaveFormat Enumeration specifies the format in which document is saved, it can be HTML, MHTML and MD formats. The method saves the HTML document in the specified format to the local file specified by path. All resources used in the document will be saved into an adjacent folder.

Source code

You can download the complete examples and data files from GitHub.

Examples

# HTML input file content
<!DOCTYPE html>
<html lang="en"
   xmlns:xml="http://www.w3.org/XML/1998/namespace">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="styles/main.css">
  <title>Title</title>
</head>
<body>
<div id="uniqueIdentifier">Container with ID - identifier</div>
<div class="custom-class">Customized by css class container</div>

<div>
  <p class="pStyle">First styled by pStyle class paragraph</p>
  <p class="pStyle">Second styled by pStyle class paragraph</p>
  <p class="pStyle">Third styled by pStyle class paragraph</p>
  <span class="pStyle">Span styled by pStyle</span>
</div>

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mrow>...</mrow>
</math>

<div id="smart class">
  <p id="p1" class="ddd kkk">Paragraph styled by class name =ddd kkk=</p>
  <p id="p2" class="ddd fff">Paragraph styled by class name =ddd fff=</p>
  <p id="p3" class="kkk fff">Paragraph styled by class name =kkk fff=</p>
</div>

</body>
</html>

# C# code
using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}
	var outputFilePath = Path.Combine(outputHtmlPath, "result.mhtml");
	document.Save(outputFilePath, HTMLSaveFormat.MHTML);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output folder path.

Content of result file

MIME-Version: 1.0

Content-Type: Multipart/related; boundary=“boundary”;type=Text/HTML

–boundary

Content-Type: text/html;

Content-Location: result.mhtml

<!DOCTYPE html><html lang=“en” xmlns:xml=“http://www.w3.org/XML/1998/namespace"&gt;&lt;head>

<meta charset=“UTF-8”>

<link rel=“stylesheet” href=“main.css”>

<title>Title</title>

</head>

<body>

<div id=“uniqueIdentifier”>Container with ID - identifier</div>

<div class=“custom-class”>Customized by css class container</div>

<div>

<p class=“pStyle”>First styled by pStyle class paragraph</p>

<p class=“pStyle”>Second styled by pStyle class paragraph</p>

<p class=“pStyle”>Third styled by pStyle class paragraph</p>

<span class=“pStyle”>Span styled by pStyle</span>

</div>

<math xmlns=“http://www.w3.org/1998/Math/MathML">

<mrow>…</mrow>

</math>

<div id=“smart class”>

<p id=“p1” class=“ddd kkk”>Paragraph styled by class name =ddd kkk=</p>

<p id=“p2” class=“ddd fff”>Paragraph styled by class name =ddd fff=</p>

<p id=“p3” class=“kkk fff”>Paragraph styled by class name =kkk fff=</p>

</div>

<div>Hello from DIV element</div></body></html>

–boundary

Content-Type: text/css;

Content-Location: main.css

.custom-class { color: yellow; background-color: blueviolet; margin-top: 10pt; margin-right: 10pt; margin-bottom: 10pt; margin-left: 10pt; }.pStyle { font-weight: bold; }.ddd { padding-top: 10pt; padding-right: 10pt; padding-bottom: 10pt; padding-left: 10pt; }.kkk { background-color: chartreuse; }

–boundary–

See Also


Save(Url, HTMLSaveFormat)

Saves the document to a local file specified by url. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as output_file_name + “_files”.

public void Save(Url url, HTMLSaveFormat saveFormat)
ParameterTypeDescription
urlUrlLocal URL to output file.
saveFormatHTMLSaveFormatFormat in which document is saved.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified url is not a valid local file URL.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(Url, HTMLSaveFormat) Method

It is necessary to specify a full Url path - ‘outputFilePath’ for HTML document saving. The Url(url) constructor creates an instance of the Url class with the specified url. The HTMLSaveFormat Enumeration specifies the format in which document is saved, it can be HTML, MHTML and MD formats. Then you should pass the parameters to the Save(url, saveFormat) method. The document will be saved in the specified format to the local file specified by url.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.mhtml");
	document.Save(new Url(outputFilePath), HTMLSaveFormat.MHTML);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output directory path.

See Also


Save(ResourceHandler, HTMLSaveFormat)

Saves the document content and resources using the ResourceHandler.

public void Save(ResourceHandler resourceHandler, HTMLSaveFormat saveFormat)
ParameterTypeDescription
resourceHandlerResourceHandlerThe resource handler ResourceHandler.
saveFormatHTMLSaveFormatFormat in which document is saved.

See Also


Save(string, HTMLSaveOptions)

Saves the document to a local file specified by path. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(string path, HTMLSaveOptions saveOptions)
ParameterTypeDescription
pathStringLocal path to output file.
saveOptionsHTMLSaveOptionsHTMLSaveOptions object is for resource handling process management.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified path is not a valid local file path.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(String, HTMLSaveOptions) Method

Save(String, HTMLSaveOptions) method takes as parameters a local file system path to output file, an instance of HTMLSaveOptions class and saves an HTML document with resources to the local file specified by path. The HTMLSaveOptions() constructor creates a save options instance that has ResourceHandlingOptions properties which are used for configuration of resources handling. All resources used in the document will be saved into an adjacent folder.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.html");
	// Define options class instance
	var options = new HTMLSaveOptions();
	// Pages handling restriction
	options.ResourceHandlingOptions.MaxHandlingDepth = 1;
	document.Save(outputFilePath, options);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output folder path.

See Also


Save(Url, HTMLSaveOptions)

Saves the document to a local file specified by url. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(Url url, HTMLSaveOptions saveOptions)
ParameterTypeDescription
urlUrlLocal URL to output file.
saveOptionsHTMLSaveOptionsHTMLSaveOptions object is for resource handling process management.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified url is not a valid local file URL.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(Url, HTMLSaveOptions) Method

It is necessary to specify a full Url path for HTML document saving. The Url(url) constructor creates an instance of the Url class with the specified url. The HTMLSaveOptions() constructor creates an instance of HTMLSaveOptions class that has ResourceHandlingOptions properties which are used for configuration of resources handling. The Save(url, saveOptions) method takes parameters and saves the HTML document with resources to the local file specified by url.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.html");
	// Define options class instance
	var options = new HTMLSaveOptions();
	// Pages handling restriction
	options.ResourceHandlingOptions.MaxHandlingDepth = 1;
	document.Save(new Url(outputFilePath), options);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output folder path.

See Also


Save(ResourceHandler, HTMLSaveOptions)

Saves the document content and resources using the ResourceHandler.

public void Save(ResourceHandler resourceHandler, HTMLSaveOptions saveOptions)
ParameterTypeDescription
resourceHandlerResourceHandlerThe resource handler ResourceHandler.
saveOptionsHTMLSaveOptionsHTML save options.

See Also


Save(string, MarkdownSaveOptions)

Saves the document to a local file specified by path. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(string path, MarkdownSaveOptions saveOptions)
ParameterTypeDescription
pathStringLocal path to output file.
saveOptionsMarkdownSaveOptionsMarkdownSaveOptions object usage enables you to tune the rendering process. For more info see the Aspose Documentation.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified path is not a valid local file path.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(String, MarkdownSaveOptions) Method

It is necessary to specify a local file system path to the output file for document saving. The MarkdownSaveOptions() constructor creates an instance of MarkdownSaveOptions class that has a set of properties. For example, you can set markdown formatting style, use predefined GitLab Flavored Markdown compatible options and configure resources handling. The Save(path, saveOptions) method takes the local file system path to output file and options instance as parameters and saves HTML as a Markdown document with resources to the local file specified by path.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
     
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.md");
	// Define options class instance
	var options = new MarkdownSaveOptions();
	document.Save(outputFilePath, options);
}

*inputHtmlPath - user input html file.

*outputHtmlPath - user output folder path.

See Also


Save(Url, MarkdownSaveOptions)

Saves the document to a local file specified by url. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(Url url, MarkdownSaveOptions saveOptions)
ParameterTypeDescription
urlUrlLocal URL to output file.
saveOptionsMarkdownSaveOptionsMarkdownSaveOptions object usage enables you to tune the rendering process. For more info see the documentation.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified url is not a valid local file URL.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(Url, MarkdownSaveOptions) Method

It is necessary to specify a full Url path for document saving. The Url(url) constructor creates an instance of the Url class with the specified url. The MarkdownSaveOptions() constructor creates an instance of MarkdownSaveOptions class that has a set of properties. For example, you can set Markdown formatting style, use predefined GitLab Flavored Markdown compatible options and configure resources handling. The Save(url, saveOptions) method takes url and save options instances as parameters and saves the document with resources to the local file specified by url.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.md");
	// Define options class instance
	var options = new MarkdownSaveOptions();
	document.Save(new Url(outputFilePath), options);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output folder path.

See Also


Save(ResourceHandler, MarkdownSaveOptions)

Saves the document content and resources using the ResourceHandler.

public void Save(ResourceHandler resourceHandler, MarkdownSaveOptions saveOptions)
ParameterTypeDescription
resourceHandlerResourceHandlerThe resource handler ResourceHandler.
saveOptionsMarkdownSaveOptionsMarkdown save options.

See Also


Save(string, MHTMLSaveOptions)

Saves the document to a local file specified by path. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(string path, MHTMLSaveOptions saveOptions)
ParameterTypeDescription
pathStringLocal path to output file.
saveOptionsMHTMLSaveOptionsMHTMLSaveOptions object usage enables you to tune the rendering process. For more info see the documentation.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified path is not a valid local file path.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(String, MHTMLSaveOptions) Method

It is necessary to specify a local file system path to the output file for document saving. The MHTMLSaveOptions() constructor initializes an instance of MHTMLSaveOptions class that has the ResourceHandlingOptions property which is used for configuration of resources handling. The Save(path, saveOptions) method takes a local file system path to output file and a save options instance as parameters and saves HTML as an MHTML document to the local file specified by path.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.mhtm");
	// Define options class instance
	var options = new MHTMLSaveOptions();
	document.Save(outputFilePath, options);
}

*inputHtmlPath - user input html file path.

*outputHtmlPath - user output folder path.

See Also


Save(Url, MHTMLSaveOptions)

Saves the document to a local file specified by url. All resources used in this document will be saved into an adjacent folder, whose name will be constructed as: output_file_name + “_files”.

public void Save(Url url, MHTMLSaveOptions saveOptions)
ParameterTypeDescription
urlUrlLocal URL to output file.
saveOptionsMHTMLSaveOptionsMHTMLSaveOptions object usage enables you to tune the rendering process. For more info see the documentation.

Exceptions

exceptioncondition
ArgumentExceptionRaised if the specified url is not a valid local file URL.

Remarks

Save HTML

Most of the tasks, you need to perform, require saving a document. Once you load the existing file or create an HTML document from scratch, you can save your changes using one of HTMLDocument.Save() methods. The methods allow saving HTML to a local file specified by path, URL, or output storage. Refer to the documentation to learn more about saving.

Save(Url, MHTMLSaveOptions) Method

It is necessary to specify a full Url path for document saving. The Url(url) constructor creates an instance of the Url class with the specified url. The MHTMLSaveOptions() constructor initializes an instance of MHTMLSaveOptions class that has the ResourceHandlingOptions property which is used for configuration of resources handling. The Save(url, saveOptions) method takes url and options as parameters and saves HTML as an MHTML document to the local file specified by url.

Source code

You can download the complete examples and data files from GitHub.

Examples

using System;
using System.IO;
using Aspose.Html;
using Aspose.Html.Saving;
...
using (var document = new HTMLDocument(inputHtmlPath))
{
	HTMLDivElement element = (HTMLDivElement) document.CreateElement("div");
	element.InnerHTML = "Hello from DIV element";
	document.Body.AppendChild(element);
         
	if (string.IsNullOrEmpty(outputHtmlPath))
	{
		throw new ArgumentException("Non valid path to output result");
	}

	var outputFilePath = Path.Combine(outputHtmlPath, "result.mhtm");
	// Define options class instance
	var options = new MHTMLSaveOptions();
	document.Save(new Url(outputFilePath), options);
}

*inputHtmlPath - user input file path.

*outputHtmlPath - user output folder path.

See Also


Save(ResourceHandler, MHTMLSaveOptions)

Saves the document content and resources using the ResourceHandler.

public void Save(ResourceHandler resourceHandler, MHTMLSaveOptions saveOptions)
ParameterTypeDescription
resourceHandlerResourceHandlerThe resource handler ResourceHandler.
saveOptionsMHTMLSaveOptionsMHTML save options.

See Also