ToMarkdown
Leave feedback
On this page
Converts a document to Markdown in a single call and returns the Markdown string. This is the simplest way to convert a file. The format is detected automatically.
public static string ToMarkdown(string sourcePath)
| Parameter | Type | Description |
|---|---|---|
| sourcePath | String | The path to the source document (e.g. "report.docx"). |
The converted Markdown content as a UTF-8 string.
| exception | condition |
|---|---|
| GroupDocsMarkdownException | Thrown when the conversion fails. |
| ArgumentNullException | Thrown when sourcePath is null or empty. |
| NotSupportedException | Thrown when the file format is not supported. |
string markdown = MarkdownConverter.ToMarkdown("document.docx");
Console.WriteLine(markdown);
- class MarkdownConverter
- namespace GroupDocs.Markdown
- assembly GroupDocs.Markdown
Converts a document to Markdown using the specified load options and returns the Markdown string. Use this overload to supply a password for encrypted documents or to specify the file format explicitly.
public static string ToMarkdown(string sourcePath, LoadOptions loadOptions)
| Parameter | Type | Description |
|---|---|---|
| sourcePath | String | The path to the source document. |
| loadOptions | LoadOptions | Options for loading the document (password, format hint). May be null. |
The converted Markdown content as a UTF-8 string.
| exception | condition |
|---|---|
| GroupDocsMarkdownException | Thrown when the conversion fails. |
| NotSupportedException | Thrown when the file format is not supported. |
var loadOptions = new LoadOptions(FileFormat.Docx) { Password = "secret" };
string markdown = MarkdownConverter.ToMarkdown("encrypted.docx", loadOptions);
- class LoadOptions
- class MarkdownConverter
- namespace GroupDocs.Markdown
- assembly GroupDocs.Markdown
Converts a document to Markdown using the specified conversion options and returns the Markdown string. Use this overload to control image handling, heading offsets, or page selection.
public static string ToMarkdown(string sourcePath, ConvertOptions convertOptions)
| Parameter | Type | Description |
|---|---|---|
| sourcePath | String | The path to the source document. |
| convertOptions | ConvertOptions | Options that customize the conversion (image strategy, heading offset, page numbers). May be null. |
The converted Markdown content as a UTF-8 string.
| exception | condition |
|---|---|
| GroupDocsMarkdownException | Thrown when the conversion fails. |
| NotSupportedException | Thrown when the file format is not supported. |
var options = new ConvertOptions { HeadingLevelOffset = 2 };
string markdown = MarkdownConverter.ToMarkdown("document.docx", options);
- class ConvertOptions
- class MarkdownConverter
- namespace GroupDocs.Markdown
- assembly GroupDocs.Markdown
Converts a document to Markdown using the specified load and conversion options, and returns the Markdown string. This is the most flexible static overload, combining format/password control with full conversion customization.
public static string ToMarkdown(string sourcePath, LoadOptions loadOptions,
ConvertOptions convertOptions)
| Parameter | Type | Description |
|---|---|---|
| sourcePath | String | The path to the source document. |
| loadOptions | LoadOptions | Options for loading the document (password, format hint). May be null. |
| convertOptions | ConvertOptions | Options that customize the conversion. May be null. |
The converted Markdown content as a UTF-8 string.
| exception | condition |
|---|---|
| GroupDocsMarkdownException | Thrown when the conversion fails. |
| NotSupportedException | Thrown when the file format is not supported. |
- class LoadOptions
- class ConvertOptions
- class MarkdownConverter
- namespace GroupDocs.Markdown
- assembly GroupDocs.Markdown
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.