Skip to content

Commit 746a4b7

Browse files
ES-957421-Find-and-replace-placeholders
1 parent 410b6a3 commit 746a4b7

File tree

78 files changed

+74919
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+74919
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-and-replace-placeholders", "Find-and-replace-placeholders\Find-and-replace-placeholders.csproj", "{BCF227BE-073C-42B3-B66D-9A932F63638F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{BCF227BE-073C-42B3-B66D-9A932F63638F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{BCF227BE-073C-42B3-B66D-9A932F63638F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{BCF227BE-073C-42B3-B66D-9A932F63638F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{BCF227BE-073C-42B3-B66D-9A932F63638F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.Diagnostics;
2+
using System.Text.RegularExpressions;
3+
using Find_and_replace_placeholders.Models;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Syncfusion.DocIO.DLS;
6+
using Syncfusion.DocIO;
7+
using Syncfusion.DocIORenderer;
8+
using Syncfusion.Pdf;
9+
10+
namespace Find_and_replace_placeholders.Controllers
11+
{
12+
public class HomeController : Controller
13+
{
14+
private readonly ILogger<HomeController> _logger;
15+
16+
public HomeController(ILogger<HomeController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
public IActionResult Index()
22+
{
23+
return View();
24+
}
25+
26+
public ActionResult CreateDocument(string firstname, string lastname, string email, string phone, string address)
27+
{
28+
//Creating a new document.
29+
using (WordDocument document = new WordDocument(new FileStream("Data/Template.docx", FileMode.Open, FileAccess.Read), FormatType.Automatic))
30+
{
31+
// Store inputs in a 1D array
32+
string[] userInputs = { firstname, lastname, email, phone, address };
33+
// Find all placeholders like "{{Name}}"
34+
TextSelection[] selections = document.FindAll(new Regex(@"\{(.*)\}"));
35+
for (int i = 0; i < selections.Count(); i++)
36+
{
37+
TextSelection selection = selections[i];
38+
//Replace the text with user values
39+
document.Replace(selection.SelectedText, userInputs[i], false, true);
40+
}
41+
//Instantiation of DocIORenderer for Word to PDF conversion
42+
using (DocIORenderer render = new DocIORenderer())
43+
{
44+
//Converts Word document into PDF document
45+
PdfDocument pdfDocument = render.ConvertToPDF(document);
46+
47+
//Saves the PDF document to MemoryStream.
48+
MemoryStream stream = new MemoryStream();
49+
pdfDocument.Save(stream);
50+
stream.Position = 0;
51+
52+
//Download PDF document in the browser.
53+
return File(stream, "application/pdf", "Sample.pdf");
54+
}
55+
}
56+
}
57+
58+
public IActionResult Privacy()
59+
{
60+
return View();
61+
}
62+
63+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
64+
public IActionResult Error()
65+
{
66+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
67+
}
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>Find_and_replace_placeholders</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="29.1.41" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<None Update="Data\Template.docx">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
20+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>https</ActiveDebugProfile>
5+
</PropertyGroup>
6+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Find_and_replace_placeholders.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
builder.Services.AddControllersWithViews();
5+
6+
var app = builder.Build();
7+
8+
// Configure the HTTP request pipeline.
9+
if (!app.Environment.IsDevelopment())
10+
{
11+
app.UseExceptionHandler("/Home/Error");
12+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
13+
app.UseHsts();
14+
}
15+
16+
app.UseHttpsRedirection();
17+
app.UseStaticFiles();
18+
19+
app.UseRouting();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllerRoute(
24+
name: "default",
25+
pattern: "{controller=Home}/{action=Index}/{id?}");
26+
27+
app.Run();
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:20701",
8+
"sslPort": 44342
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5211",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7239;http://localhost:5211",
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1" />
10+
<title>@ViewData["Title"]</title>
11+
<style>
12+
body {
13+
font-family: Arial, sans-serif;
14+
background-color: #f4f4f4;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
19+
.form-container {
20+
width: 400px;
21+
margin: 50px auto;
22+
padding: 20px;
23+
background-color: white;
24+
border-radius: 8px;
25+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
26+
}
27+
28+
.form-container label {
29+
font-weight: bold;
30+
display: block;
31+
margin-bottom: 5px;
32+
}
33+
34+
.form-container input[type="text"],
35+
.form-container input[type="email"] {
36+
width: 100%;
37+
padding: 10px;
38+
margin-bottom: 20px;
39+
border: 1px solid #ddd;
40+
border-radius: 4px;
41+
}
42+
43+
.form-container input[type="submit"] {
44+
width: 100%;
45+
padding: 12px;
46+
background-color: #007BFF;
47+
color: white;
48+
border: none;
49+
border-radius: 4px;
50+
font-size: 16px;
51+
cursor: pointer;
52+
}
53+
54+
.form-container input[type="submit"]:hover {
55+
background-color: #0056b3;
56+
}
57+
</style>
58+
</head>
59+
<body>
60+
61+
<div class="form-container">
62+
@using (Html.BeginForm("CreateDocument", "Home", FormMethod.Get))
63+
{
64+
<label for="firstname">First Name:</label>
65+
<input type="text" id="firstname" name="firstname" required />
66+
67+
<label for="lastname">Last Name:</label>
68+
<input type="text" id="lastname" name="lastname" required />
69+
70+
<label for="email">Email:</label>
71+
<input type="email" id="email" name="email" required />
72+
73+
<label for="phone">Phone:</label>
74+
<input type="text" id="phone" name="phone" required />
75+
76+
<label for="address">Address:</label>
77+
<input type="text" id="address" name="address" required />
78+
79+
<input type="submit" value="Create Document" />
80+
}
81+
</div>
82+
83+
</body>
84+
</html>
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>
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - Find_and_replace_placeholders</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/Find_and_replace_placeholders.styles.css" asp-append-version="true" />
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container-fluid">
15+
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Find_and_replace_placeholders</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
24+
</li>
25+
<li class="nav-item">
26+
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
27+
</li>
28+
</ul>
29+
</div>
30+
</div>
31+
</nav>
32+
</header>
33+
<div class="container">
34+
<main role="main" class="pb-3">
35+
@RenderBody()
36+
</main>
37+
</div>
38+
39+
<footer class="border-top footer text-muted">
40+
<div class="container">
41+
&copy; 2025 - Find_and_replace_placeholders - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
42+
</div>
43+
</footer>
44+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
45+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
46+
<script src="~/js/site.js" asp-append-version="true"></script>
47+
@await RenderSectionAsync("Scripts", required: false)
48+
</body>
49+
</html>

0 commit comments

Comments
 (0)