DEV Community

GroupDocs
GroupDocs

Posted on

1

Editing Documents in Multi-threaded Environment using C# .NET API

Editing different types of documents programmatically on different development platforms is almost a given when talking about document manipulation in general. Most basic requirement is to modify file contents, then re-convert the file to original or even a different format too. Add to it some other perks like multiple sources for loading documents, securing the resultant documents and so on.

So, an API offering document editing features plus the document we wish to edit is all we need to get started. If .NET platform is your forte, you can try GroupDocs.Editor for .NET API, which is a feature rich file editor helping you in developing simple, scalable C# and ASP.NET apps which integrate with different HTML based editors to modify your Microsoft Word, Excel, OpenDocument, Text, HTML and other types of documents.

Latest release of this .NET API supports a refined set of lists and paragraphs to use in HTML editors. Additionally, you have access to a more stable multi-threading environment thus allowing you to further enhance your document editing experience.

Following code snippet shows how you can obtain HTML document with along with its embedded resources:
public static void GetHTMLContentsWithEmbeddedResources()
{
// 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 with embedded resources
string cssContent = htmlDoc.GetEmbeddedHtml();
Console.WriteLine(cssContent);
}
// close stream object to release file for other methods.
sourceStream.Close();
}

More help along with sample codes is available at this docs resource - http://bit.ly/2GBKvvk

Similarly, if you are looking to convert HTML DOM to a document, please refer to below code snippet. Which specifically gets HTML DOM from string content and saves it to a document:

public static void GetHTMLDOMContentsToDocument()
{
// 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();
EditorHandler.ToDocument(editedHtmlDoc, outputStream, saveOptions);
}
}
}
// close stream object to release file for other methods.
sourceStream.Close();
}

Try free today – http://bit.ly/2DZY99S

Follow GroupDocs on YouTube – http://bit.ly/2UPmVPr

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Oldest comments (0)

Image of Timescale

📊 Benchmarking Databases for Real-Time Analytics Applications

Benchmarking Timescale, Clickhouse, Postgres, MySQL, MongoDB, and DuckDB for real-time analytics. Introducing RTABench 🚀

Read full post →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay