DEV Community

GroupDocs
GroupDocs

Posted on

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

Top comments (0)