Skip to content

Commit fb00ff4

Browse files
Merge pull request #570 from SyncfusionExamples/1031944-Modify-Markdown-conversion-file-Path
Task(1031944) - Update Markdown samples in Word Library
2 parents 4f9f00e + 966fe32 commit fb00ff4

8 files changed

Lines changed: 31 additions & 76 deletions

File tree

  • Markdown-to-Word-conversion
    • Convert-Markdown-to-Word/.NET/Convert-Markdown-to-Word
    • Customize-image/.NET/Customize-image
  • Word-to-Markdown-conversion
    • Block-quote-in-Markdown/.NET/Block-quote-in-Markdown
    • Code-block-in-Markdown/.NET/Code-block-in-Markdown
    • Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown
    • Customize-image-path/.NET/Customize-image-path
    • Export-images-to-folder/.NET/Export-images-to-folder
  • Word-to-PDF-Conversion/Convert-Word-document-to-PDF/.NET/Convert-Word-document-to-PDF

Markdown-to-Word-conversion/Convert-Markdown-to-Word/.NET/Convert-Markdown-to-Word/Program.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ class Program
88
{
99
static void Main(string[] args)
1010
{
11-
//Open a file as a stream.
12-
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.md"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
11+
// Open an existing Markdown file.
12+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Input.md")))
1313
{
14-
//Load the file stream into a Markdown file.
15-
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Markdown))
16-
{
17-
//Create a file stream.
18-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/MarkdownToWord.docx"), FileMode.Create, FileAccess.ReadWrite))
19-
{
20-
//Save a Word document to the file stream.
21-
document.Save(outputFileStream, FormatType.Docx);
22-
}
23-
}
14+
// Save as a Word document.
15+
document.Save(Path.GetFullPath(@"Output/MarkdownToWord.docx"), FormatType.Docx);
2416
}
2517
}
2618
}

Markdown-to-Word-conversion/Customize-image/.NET/Customize-image/Program.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ static void Main(string[] args)
1616
//Hook the event to customize the image while importing Markdown.
1717
document.MdImportSettings.ImageNodeVisited += MdImportSettings_ImageNodeVisited;
1818
//Open the Markdown file.
19-
document.Open(new FileStream(Path.GetFullPath("Data/Input.md"), FileMode.Open, FileAccess.Read), FormatType.Markdown);
20-
21-
//Create a file stream.
22-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Sample.docx"), FileMode.Create, FileAccess.ReadWrite))
23-
{
24-
//Save a Markdown file to the file stream.
25-
document.Save(outputFileStream, FormatType.Docx);
26-
}
19+
document.Open(Path.GetFullPath("Data/Input.md"));
20+
//Save as a Word document.
21+
document.Save(Path.GetFullPath(@"../../../Output/Output.docx"));
2722
}
2823
}
2924
private static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)

Word-to-Markdown-conversion/Block-quote-in-Markdown/.NET/Block-quote-in-Markdown/Program.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ static void Main(string[] args)
2121
paragraph.ApplyStyle("Quote");
2222
//Append text.
2323
IWTextRange textRange = paragraph.AppendText("Hello World");
24-
//Create a file stream.
25-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.md"), FileMode.Create, FileAccess.ReadWrite))
26-
{
27-
//Save the Markdown file to the file stream.
28-
document.Save(outputFileStream, FormatType.Markdown);
29-
}
24+
//Save the document as a Markdown file.
25+
document.Save(Path.GetFullPath(@"Output/Output.md"));
3026
}
3127
}
3228
}

Word-to-Markdown-conversion/Code-block-in-Markdown/.NET/Code-block-in-Markdown/Program.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ static void Main(string[] args)
3535
paragraph.ApplyStyle("IndentedCode");
3636
//Append text.
3737
textRange = paragraph.AppendText("class Hello\n\t{\n\t\tStatic void Main()\n\t\t{\n\t\t\tConsole.WriteLine(\"Indented Code\")\n\t\t}\n\t}");
38-
//Create a file stream.
39-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.md"), FileMode.Create, FileAccess.ReadWrite))
40-
{
41-
//Save the Markdown file to the file stream.
42-
document.Save(outputFileStream, FormatType.Markdown);
43-
}
38+
//Save the document as a Markdown file.
39+
document.Save(Path.GetFullPath(@"Output/Output.md"));
4440
}
4541
}
4642
}

Word-to-Markdown-conversion/Convert-Word-to-Markdown/.NET/Convert-Word-to-Markdown/Program.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@ class Program
88
{
99
static void Main(string[] args)
1010
{
11-
//Open a file as a stream.
12-
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
11+
//Open an existing Word document.
12+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Input.docx")))
1313
{
14-
//Load the file stream into a Word document.
15-
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
16-
{
17-
//Create a file stream.
18-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.md"), FileMode.Create, FileAccess.ReadWrite))
19-
{
20-
//Save a Markdown file to the file stream.
21-
document.Save(outputFileStream, FormatType.Markdown);
22-
}
23-
}
24-
}
14+
//Save the document as a Markdown file.
15+
document.Save(Path.GetFullPath(@"Output/Output.md"));
16+
}
2517
}
2618
}
2719
}

Word-to-Markdown-conversion/Customize-image-path/.NET/Customize-image-path/Program.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Syncfusion.DocIO;
22
using Syncfusion.DocIO.DLS;
33
using Syncfusion.Drawing;
4+
using Syncfusion.Office.Markdown;
45
using System.IO;
56

67
namespace Customize_image_path
@@ -9,25 +10,17 @@ class Program
910
{
1011
static void Main(string[] args)
1112
{
12-
//Open a file as a stream.
13-
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
//Load the file stream into a Word document.
14+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Input.docx")))
1415
{
15-
//Load the file stream into a Word document.
16-
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
17-
{
18-
//Create a file stream.
19-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.md"), FileMode.Create, FileAccess.ReadWrite))
20-
{
21-
//Hook the event to customize the image.
22-
document.SaveOptions.ImageNodeVisited += SaveImage;
23-
//Save a Markdown file to the file stream.
24-
document.Save(outputFileStream, FormatType.Markdown);
25-
}
26-
}
16+
//Hook the event to customize the image.
17+
document.SaveOptions.MarkdownSaveOptions.ImageNodeVisited += SaveImage;
18+
//Save a Markdown file to the file stream.
19+
document.Save(Path.GetFullPath(@"Output/Output.md"));
2720
}
2821
}
2922
//The following code examples show the event handler to customize the image path and save the image in an external folder.
30-
static void SaveImage(object sender, ImageNodeVisitedEventArgs args)
23+
static void SaveImage(object sender, MdImageNodeVisitedEventArgs args)
3124
{
3225
string imagepath = Path.GetFullPath(@"Output/Output.png");
3326
//Save the image stream as a file.

Word-to-Markdown-conversion/Export-images-to-folder/.NET/Export-images-to-folder/Program.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,13 @@ class Program
1010
{
1111
static void Main(string[] args)
1212
{
13-
//Open a file as a stream.
14-
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
//Open an existing Word document.
14+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Input.docx")))
1515
{
16-
//Load the file stream into a Word document.
17-
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
18-
{
19-
//Create a file stream.
20-
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.md"), FileMode.Create, FileAccess.ReadWrite))
21-
{
22-
//Set images folder to export images.
23-
document.SaveOptions.MarkdownExportImagesFolder = Path.GetFullPath(@"Output/");
24-
//Save a Markdown file to the file stream.
25-
document.Save(outputFileStream, FormatType.Markdown);
26-
}
27-
}
16+
//Set images folder to export images.
17+
document.SaveOptions.MarkdownExportImagesFolder = Path.GetFullPath(@"Output/");
18+
//Save the document as a Markdown file.
19+
document.Save(Path.GetFullPath(@"Output/Output.md"));
2820
}
2921
}
3022
}

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/.NET/Convert-Word-document-to-PDF/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Syncfusion.DocIO;
2-
using Syncfusion.DocIO.DLS;
1+
using Syncfusion.DocIO.DLS;
32
using Syncfusion.DocIORenderer;
43
using Syncfusion.Pdf;
54
using System.IO;

0 commit comments

Comments
 (0)