Skip to content

Commit 1263092

Browse files
committed
Added the sample for youTube video.
1 parent 8ae8a0e commit 1263092

78 files changed

Lines changed: 79749 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using WordToRTF.Models;
4+
using Syncfusion.DocIO;
5+
using Syncfusion.DocIO.DLS;
6+
7+
namespace WordToRTF.Controllers
8+
{
9+
public class HomeController : Controller
10+
{
11+
private readonly ILogger<HomeController> _logger;
12+
13+
public HomeController(ILogger<HomeController> logger)
14+
{
15+
_logger = logger;
16+
}
17+
18+
public IActionResult WordToRTF()
19+
{
20+
// Open the Word document as a file stream
21+
FileStream fileStream = new FileStream("Data\\Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
22+
23+
// Load the stream into a DocIO WordDocument instance
24+
WordDocument document = new WordDocument(fileStream, FormatType.Docx);
25+
26+
// Create a memory stream to store the converted RTF content
27+
MemoryStream outputStream = new MemoryStream();
28+
29+
// Save the document in RTF format
30+
document.Save(outputStream, FormatType.Rtf);
31+
32+
// Close the document to release resources
33+
document.Close();
34+
35+
// Return the downloadable file
36+
return File(outputStream, "application/rtf", "WordToRTF.rtf");
37+
}
38+
39+
public IActionResult RTFToWord()
40+
{
41+
// Open the RTF file as a file stream
42+
FileStream fileStream = new FileStream("Data\\Input.rtf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
43+
44+
// Load the stream into a DocIO WordDocument instance
45+
WordDocument document = new WordDocument(fileStream, FormatType.Rtf);
46+
47+
// Create a memory stream to store the converted Word content
48+
MemoryStream outputStream = new MemoryStream();
49+
50+
// Save the document in DOCX format
51+
document.Save(outputStream, FormatType.Docx);
52+
53+
// Close the document to release resources
54+
document.Close();
55+
56+
// Return the downloadable file
57+
return File(outputStream, "application/docx", "RTFToWord.docx");
58+
}
59+
60+
public IActionResult Index()
61+
{
62+
return View();
63+
}
64+
65+
public IActionResult Privacy()
66+
{
67+
return View();
68+
}
69+
70+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
71+
public IActionResult Error()
72+
{
73+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
74+
}
75+
}
76+
}

Videos/WordToRTF/Data/Input.rtf

Lines changed: 4893 additions & 0 deletions
Large diffs are not rendered by default.
349 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace WordToRTF.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}

Videos/WordToRTF/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace WordToRTF
2+
{
3+
public class Program
4+
{
5+
public static void Main(string[] args)
6+
{
7+
var builder = WebApplication.CreateBuilder(args);
8+
9+
// Add services to the container.
10+
builder.Services.AddControllersWithViews();
11+
12+
var app = builder.Build();
13+
14+
// Configure the HTTP request pipeline.
15+
if (!app.Environment.IsDevelopment())
16+
{
17+
app.UseExceptionHandler("/Home/Error");
18+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
19+
app.UseHsts();
20+
}
21+
22+
app.UseHttpsRedirection();
23+
app.UseStaticFiles();
24+
25+
app.UseRouting();
26+
27+
app.UseAuthorization();
28+
29+
app.MapControllerRoute(
30+
name: "default",
31+
pattern: "{controller=Home}/{action=Index}/{id?}");
32+
33+
app.Run();
34+
}
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:49231",
8+
"sslPort": 44321
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5241",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7158;http://localhost:5241",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}

Videos/WordToRTF/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# How to Convert a Word Document to an RTF File Using the .NET Word Library
2+
3+
This repository provides an example of how to convert a Word document to RTF, and an RTF file to a Word document using the **Syncfusion .NET Word Library (DocIO)**.
4+
5+
## Process Behind Word–RTF Conversion
6+
7+
This sample shows how easily you can switch between Word (.docx) and Rich Text Format (.rtf) using the Syncfusion DocIO library. These conversions are useful when you need to:
8+
9+
- Share documents in a lightweight, widely supported RTF format.
10+
- Preserve text formatting while avoiding the full complexity of a DOCX file.
11+
- Integrate RTF files into applications that require plain rich-text formatting.
12+
13+
Using the Syncfusion DocIO library, you can:
14+
15+
- Convert a Word document (.docx) to an RTF file (.rtf).
16+
- Convert an RTF file (.rtf) back to a Word document (.docx).
17+
18+
## Steps to use the sample
19+
20+
1. Open the ASP.NET Core application where the Syncfusion DocIO package is installed.
21+
2. Run the application and click the following buttons:
22+
- **Word to RTF**: Converts an existing Word document to an RTF file.
23+
- **RTF to Word**: Converts an existing RTF file back to a Word document.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div>
6+
<h2 style="margin-bottom: 20px"> Word to RTF Conversions </h2>
7+
<div>
8+
<button style="width: 200px; margin-bottom: 20px; height: 40px;display:block;font-size:18px;"
9+
onclick="location.href='@Url.Action("WordToRTF", "Home")'">
10+
Word to RTF
11+
</button>
12+
<button style="width: 200px; margin-bottom: 20px; height: 40px;display:block;font-size:18px;"
13+
onclick="location.href='@Url.Action("RTFToWord", "Home")'">
14+
RTF to Word
15+
</button>
16+
</div>
17+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@{
2+
ViewData["Title"] = "Privacy Policy";
3+
}
4+
<h1>@ViewData["Title"]</h1>
5+
6+
<p>Use this page to detail your site's privacy policy.</p>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@model ErrorViewModel
2+
@{
3+
ViewData["Title"] = "Error";
4+
}
5+
6+
<h1 class="text-danger">Error.</h1>
7+
<h2 class="text-danger">An error occurred while processing your request.</h2>
8+
9+
@if (Model.ShowRequestId)
10+
{
11+
<p>
12+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
13+
</p>
14+
}
15+
16+
<h3>Development Mode</h3>
17+
<p>
18+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
19+
</p>
20+
<p>
21+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
22+
It can result in displaying sensitive information from exceptions to end users.
23+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
24+
and restarting the app.
25+
</p>

0 commit comments

Comments
 (0)