Skip to content

Commit 78b0b7d

Browse files
Merge pull request #126 from Karan-SF4772/master
973380 - Added sample for WEB API in Getting started
2 parents 41785bc + 0bf8128 commit 78b0b7d

File tree

13 files changed

+319
-0
lines changed

13 files changed

+319
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36518.9 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client-Application", "Client-Application\Client-Application.csproj", "{7E1A6917-45FA-4AD0-A5F0-8DC5E54CFF73}"
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+
{7E1A6917-45FA-4AD0-A5F0-8DC5E54CFF73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7E1A6917-45FA-4AD0-A5F0-8DC5E54CFF73}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7E1A6917-45FA-4AD0-A5F0-8DC5E54CFF73}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7E1A6917-45FA-4AD0-A5F0-8DC5E54CFF73}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B525455D-54D4-4512-98EC-0505281BC920}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Client_Application</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+

2+
class Program
3+
{
4+
static async Task Main(string[] args)
5+
{
6+
// Create an HttpClient instance
7+
using (HttpClient client = new HttpClient())
8+
{
9+
try
10+
{
11+
// Send a GET request to a URL
12+
HttpResponseMessage response = await client.GetAsync("https://localhost:7073/api/Values/api/PowerPoint");
13+
14+
// Check if the response is successful
15+
if (response.IsSuccessStatusCode)
16+
{
17+
// Read the content as a string
18+
Stream responseBody = await response.Content.ReadAsStreamAsync();
19+
FileStream fileStream = File.Create("../../../Output/Output.pptx");
20+
responseBody.CopyTo(fileStream);
21+
fileStream.Close();
22+
}
23+
else
24+
{
25+
Console.WriteLine("HTTP error status code: " + response.StatusCode);
26+
}
27+
}
28+
catch (HttpRequestException e)
29+
{
30+
Console.WriteLine("Request exception: " + e.Message);
31+
}
32+
}
33+
}
34+
35+
}
36+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36518.9 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-PowerPoint-presentation", "Create-PowerPoint-presentation\Create-PowerPoint-presentation.csproj", "{5FB660D6-491B-4492-86AF-F12FE74559F1}"
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+
{5FB660D6-491B-4492-86AF-F12FE74559F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5FB660D6-491B-4492-86AF-F12FE74559F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5FB660D6-491B-4492-86AF-F12FE74559F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5FB660D6-491B-4492-86AF-F12FE74559F1}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {45C04AEF-6AD5-4639-8CDE-A96266A085DC}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Syncfusion.Presentation;
4+
5+
6+
namespace Create_PowerPoint_presentation.Controllers
7+
{
8+
[Route("api/[controller]")]
9+
[ApiController]
10+
public class ValuesController : ControllerBase
11+
{
12+
[HttpGet]
13+
[Route("api/PowerPoint")]
14+
public IActionResult CreatePresentation()
15+
{
16+
try
17+
{
18+
var fileDownloadName = "Output.pptx";
19+
const string contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
20+
var stream = GeneratePresentation();
21+
stream.Position = 0;
22+
return File(stream, contentType, fileDownloadName);
23+
}
24+
catch (Exception ex)
25+
{
26+
return BadRequest("Error occurred while creating PowerPoint file: " + ex.Message);
27+
}
28+
}
29+
public static MemoryStream GeneratePresentation()
30+
{
31+
// Create a new instance of PowerPoint Presentation file
32+
IPresentation pptxDoc = Presentation.Create();
33+
// Add a new slide to file and apply background color
34+
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleOnly);
35+
// Specify the fill type and fill color for the slide background
36+
slide.Background.Fill.FillType = FillType.Solid;
37+
slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229);
38+
// Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide
39+
IShape titleShape = slide.Shapes[0] as IShape;
40+
titleShape.TextBody.AddParagraph("Company History").HorizontalAlignment = HorizontalAlignmentType.Center;
41+
// Add description content to the slide by adding a new TextBox IShape
42+
IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70);
43+
descriptionShape.TextBody.Text = "IMN Solutions PVT LTD is the software company, established in 1987, by George Milton. The company has been listed as the trusted partner for many high-profile organizations since 1988 and got awards for quality products from reputed organizations.";
44+
// Add bullet points to the slide
45+
IShape bulletPointsShape = slide.AddTextBox(53.22, 270, 437.90, 116.32);
46+
// Add a paragraph for a bullet point
47+
IParagraph firstPara = bulletPointsShape.TextBody.AddParagraph("The company acquired the MCY corporation for 20 billion dollars and became the top revenue maker for the year 2015.");
48+
// Format how the bullets should be displayed
49+
firstPara.ListFormat.Type = ListType.Bulleted;
50+
firstPara.LeftIndent = 35;
51+
firstPara.FirstLineIndent = -35;
52+
// Add another paragraph for the next bullet point
53+
IParagraph secondPara = bulletPointsShape.TextBody.AddParagraph("The company is participating in top open source projects in automation industry.");
54+
// Format how the bullets should be displayed
55+
secondPara.ListFormat.Type = ListType.Bulleted;
56+
secondPara.LeftIndent = 35;
57+
secondPara.FirstLineIndent = -35;
58+
// Add an auto-shape to the slide
59+
IShape stampShape = slide.Shapes.AddShape(AutoShapeType.Explosion1, 48.93, 430.71, 104.13, 80.54);
60+
// Format the auto-shape color by setting the fill type and text
61+
stampShape.Fill.FillType = FillType.None;
62+
stampShape.TextBody.AddParagraph("IMN").HorizontalAlignment = HorizontalAlignmentType.Center;
63+
// Save the PowerPoint Presentation as stream
64+
MemoryStream stream = new MemoryStream();
65+
pptxDoc.Save(stream);
66+
pptxDoc.Close();
67+
stream.Position = 0;
68+
return stream;
69+
}
70+
}
71+
}
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace Create_PowerPoint_presentation.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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>Create_PowerPoint_presentation</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
12+
<PackageReference Include="Syncfusion.Presentation.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@Create_PowerPoint_presentation_HostAddress = http://localhost:5253
2+
3+
GET {{Create_PowerPoint_presentation_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllers();
24+
25+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:21811",
8+
"sslPort": 44317
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5253",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"https": {
23+
"commandName": "Project",
24+
"dotnetRunMessages": true,
25+
"launchBrowser": true,
26+
"launchUrl": "swagger",
27+
"applicationUrl": "https://localhost:7073;http://localhost:5253",
28+
"environmentVariables": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
}
31+
},
32+
"IIS Express": {
33+
"commandName": "IISExpress",
34+
"launchBrowser": true,
35+
"launchUrl": "swagger",
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)