Skip to content

Commit 5be214f

Browse files
author
Konduru Keerthi Konduru Ravichandra Raju
committed
DropBox Cloud Storage
1 parent ab4e6f1 commit 5be214f

File tree

156 files changed

+149970
-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.

156 files changed

+149970
-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.10.34928.147
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open-Word-document", "Open-Word-document\Open-Word-document.csproj", "{DFE40671-DF40-4CBB-BB70-76BEA875D8F8}"
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+
{DFE40671-DF40-4CBB-BB70-76BEA875D8F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DFE40671-DF40-4CBB-BB70-76BEA875D8F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DFE40671-DF40-4CBB-BB70-76BEA875D8F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DFE40671-DF40-4CBB-BB70-76BEA875D8F8}.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 = {76D3297C-9553-4014-A381-B7545DD87CBA}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using Dropbox.Api;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Caching.Memory;
4+
using Open_Word_document.Models;
5+
using Syncfusion.DocIO.DLS;
6+
using System.Diagnostics;
7+
8+
namespace Open_Word_document.Controllers
9+
{
10+
public class HomeController : Controller
11+
{
12+
private readonly ILogger<HomeController> _logger;
13+
14+
public HomeController(ILogger<HomeController> logger)
15+
{
16+
_logger = logger;
17+
}
18+
19+
public IActionResult Index()
20+
{
21+
return View();
22+
}
23+
public async Task<IActionResult> EditDocument()
24+
{
25+
try
26+
{
27+
//Retrieve the document from DropBox
28+
MemoryStream stream = await GetDocumentFromDropBox();
29+
30+
//Set the position to the beginning of the MemoryStream
31+
stream.Position = 0;
32+
33+
//Create an instance of WordDocument
34+
using (WordDocument wordDocument = new WordDocument(stream, Syncfusion.DocIO.FormatType.Docx))
35+
{
36+
//Access the section in a Word document
37+
IWSection section = wordDocument.Sections[0];
38+
39+
//Add new paragraph to the section
40+
IWParagraph paragraph = section.AddParagraph();
41+
paragraph.ParagraphFormat.FirstLineIndent = 36;
42+
paragraph.BreakCharacterFormat.FontSize = 12f;
43+
44+
//Add new text to the paragraph
45+
IWTextRange textRange = paragraph.AppendText("In 2000, AdventureWorks Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the AdventureWorks Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as IWTextRange;
46+
textRange.CharacterFormat.FontSize = 12f;
47+
48+
//Saving the Word document to a MemoryStream
49+
MemoryStream outputStream = new MemoryStream();
50+
wordDocument.Save(outputStream, Syncfusion.DocIO.FormatType.Docx);
51+
52+
//Download the Word file in the browser
53+
FileStreamResult fileStreamResult = new FileStreamResult(outputStream, "application/msword");
54+
fileStreamResult.FileDownloadName = "EditWord.docx";
55+
return fileStreamResult;
56+
}
57+
}
58+
catch (Exception ex)
59+
{
60+
Console.WriteLine($"Error: {ex.Message}");
61+
return Content("Error occurred while processing the file.");
62+
}
63+
}
64+
/// <summary>
65+
/// Download file from DropBox cloud storage
66+
/// </summary>
67+
/// <returns></returns>
68+
public async Task<MemoryStream> GetDocumentFromDropBox()
69+
{
70+
//Define the access token for authentication with the Dropbox API
71+
var accessToken = "Access_Token";
72+
73+
//Define the file path in Dropbox where the file is located
74+
var filePathInDropbox = "FilePath";
75+
76+
try
77+
{
78+
//Create a new DropboxClient instance using the provided access token
79+
using (var dbx = new DropboxClient(accessToken))
80+
{
81+
//Start a download request for the specified file in Dropbox
82+
using (var response = await dbx.Files.DownloadAsync(filePathInDropbox))
83+
{
84+
//Get the content of the downloaded file as a stream
85+
var content = await response.GetContentAsStreamAsync();
86+
87+
MemoryStream stream = new MemoryStream();
88+
content.CopyTo(stream);
89+
return stream;
90+
}
91+
}
92+
}
93+
catch (Exception ex)
94+
{
95+
Console.WriteLine($"Error retrieving document from DropBox: {ex.Message}");
96+
throw; // or handle the exception as needed
97+
}
98+
}
99+
100+
public IActionResult Privacy()
101+
{
102+
return View();
103+
}
104+
105+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
106+
public IActionResult Error()
107+
{
108+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
109+
}
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Open_Word_document.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,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>Open_Word_document</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Dropbox.Api" Version="*" />
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace Open_Word_document
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+
}
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:63599",
8+
"sslPort": 44350
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5259",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7022;http://localhost:5259",
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,12 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
@{Html.BeginForm("EditDocument", "Home", FormMethod.Get);
6+
{
7+
<div>
8+
<input type="submit" value="Edit Document" style="width:150px;height:27px" />
9+
</div>
10+
}
11+
Html.EndForm();
12+
}
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"] - Open_Word_document</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="~/Open_Word_document.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">Open_Word_document</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; 2024 - Open_Word_document - <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)