Skip to content

Commit 5590e46

Browse files
committed
1000615: Visible the storage document in core and MVC document editor
1 parent d5e3b7c commit 5590e46

15 files changed

Lines changed: 1967 additions & 3 deletions

Document-Processing-toc.html

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,8 +2852,30 @@
28522852
<li><a href="/document-processing/word/word-processor/asp-net-core/overview">Overview</a></li>
28532853
<li><a href="/document-processing/word/word-processor/asp-net-core/getting-started-core">Getting Started</a></li>
28542854
<li><a href="/document-processing/word/word-processor/asp-net-core/feature-module">Feature modules</a></li>
2855-
<li><a href="/document-processing/word/word-processor/asp-net-core/import">Import</a></li>
2856-
<li><a href="/document-processing/word/word-processor/asp-net-core/export">Export</a></li>
2855+
<li>
2856+
<a href="/document-processing/word/word-processor/asp-net-core/import">Opening Document</a>
2857+
<ul>
2858+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/azure-blob-storage">From Microsoft Azure Blob Storage</a></li>
2859+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/aws-s3-bucket">From AWS S3</a></li>
2860+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/box-cloud-file-storage">From Box cloud file storage</a></li>
2861+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/dropbox-cloud-file-storage">From Dropbox cloud file storage</a></li>
2862+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/google-cloud-storage">From Google Cloud Storage</a></li>
2863+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/google-drive">From Google Drive</a></li>
2864+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/one-drive">From One Drive</a></li>
2865+
</ul>
2866+
</li>
2867+
<li>
2868+
<a href="/document-processing/word/word-processor/asp-net-core/export">Saving Document</a>
2869+
<ul>
2870+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/azure-blob-storage">To Microsoft Azure Blob Storage</a></li>
2871+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/aws-s3-bucket">To AWS S3</a></li>
2872+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/box-cloud-file-storage">To Box cloud file storage</a></li>
2873+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/dropbox-cloud-file-storage">To Dropbox cloud file storage</a></li>
2874+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/google-cloud-storage">To Google Cloud Storage</a></li>
2875+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/google-drive">To Google Drive</a></li>
2876+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/one-drive">To One Drive</a></li>
2877+
</ul>
2878+
</li>
28572879
<li><a href="/document-processing/word/word-processor/asp-net-core/collaborative-editing/overview">Collaborative Editing</a>
28582880
<ul>
28592881
<li><a href="/document-processing/word/word-processor/asp-net-core/collaborative-editing/using-redis-cache-asp-net">Using Redis in ASP.NET Core</a></li>
@@ -2957,7 +2979,18 @@
29572979
<li><a href="/document-processing/word/word-processor/asp-net-mvc/opening-documents/one-drive">From One Drive</a></li>
29582980
</ul>
29592981
</li>
2960-
<li><a href="/document-processing/word/word-processor/asp-net-mvc/export">Export</a></li>
2982+
<li>
2983+
<a href="/document-processing/word/word-processor/asp-net-mvc/export">Saving Document</a>
2984+
<ul>
2985+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/azure-blob-storage">To Microsoft Azure Blob Storage</a></li>
2986+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/aws-s3-bucket">To AWS S3</a></li>
2987+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/box-cloud-file-storage">To Box cloud file storage</a></li>
2988+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/dropbox-cloud-file-storage">To Dropbox cloud file storage</a></li>
2989+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/google-cloud-storage">To Google Cloud Storage</a></li>
2990+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/google-drive">To Google Drive</a></li>
2991+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/one-drive">To One Drive</a></li>
2992+
</ul>
2993+
</li>
29612994
<li><a href="/document-processing/word/word-processor/asp-net-mvc/collaborative-editing/overview">Collaborative Editing</a>
29622995
<ul>
29632996
<li><a href="/document-processing/word/word-processor/asp-net-mvc/collaborative-editing/using-redis-cache-asp-net">Using Redis in ASP.NET MVC</a></li>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
layout: post
3+
title: Open document from AWS S3 in ASP.NET Core Document editor | Syncfusion
4+
description: Learn about how to Open document from AWS S3 in ASP.NET Core Document editor control of Syncfusion Essential JS 2 and more details.
5+
platform: document-processing
6+
control: Open document from AWS S3
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Open document from AWS S3
12+
13+
To load a document from AWS S3 in a Document Editor, you can follow the steps below
14+
15+
16+
**Step 1:** Create a Simple Document Editor Sample in ASP.NET Core
17+
18+
Start by following the steps provided in this [link](../../document-editor/getting-started-core) to create a simple Document Editor sample in ASP.NET Core. This will give you a basic setup of the Document Editor component.
19+
20+
21+
22+
**Step 2:** Modify the `DocumentEditorController.cs` File in the Web Service Project
23+
24+
* Open the `DocumentEditorController.cs` file in your web service project.
25+
26+
* Import the required namespaces at the top of the file:
27+
28+
```csharp
29+
using System.IO;
30+
using Amazon;
31+
using Amazon.S3;
32+
using Amazon.S3.Model;
33+
```
34+
35+
* Add the following private fields and constructor parameters to the `DocumentEditorController` class, In the constructor, assign the values from the configuration to the corresponding fields
36+
37+
```csharp
38+
private IConfiguration _configuration;
39+
public readonly string _accessKey;
40+
public readonly string _secretKey;
41+
public readonly string _bucketName;
42+
43+
public DocumentEditorController(IWebHostEnvironment hostingEnvironment, IMemoryCache cache, IConfiguration configuration)
44+
{
45+
_hostingEnvironment = hostingEnvironment;
46+
_cache = cache;
47+
_configuration = configuration;
48+
_accessKey = _configuration.GetValue<string>("AccessKey");
49+
_secretKey = _configuration.GetValue<string>("SecretKey");
50+
_bucketName = _configuration.GetValue<string>("BucketName");
51+
}
52+
```
53+
54+
* Create the `LoadFromS3()` method to load the document from AWS S3.
55+
56+
```csharp
57+
58+
[AcceptVerbs("Post")]
59+
[HttpPost]
60+
[EnableCors("AllowAllOrigins")]
61+
[Route("LoadFromS3")]
62+
//Post action for Loading the documents
63+
64+
public async Task<string> LoadFromS3([FromBody] Dictionary<string, string> onObject)
65+
{
66+
MemoryStream stream = new MemoryStream();
67+
68+
if (jsonObject == null && !jsonObject.ContainsKey("documentName"))
69+
{
70+
return null;
71+
}
72+
RegionEndpoint bucketRegion = RegionEndpoint.USEast1;
73+
74+
// Configure the AWS SDK with your access credentials and other settings
75+
var s3Client = new AmazonS3Client(_accessKey, _secretKey, bucketRegion);
76+
77+
string documentName = jsonObject["documentName"];
78+
79+
// Specify the document name or retrieve it from a different source
80+
var response = await s3Client.GetObjectAsync(_bucketName, documentName);
81+
82+
Stream responseStream = response.ResponseStream;
83+
responseStream.CopyTo(stream);
84+
stream.Seek(0, SeekOrigin.Begin);
85+
WordDocument document = WordDocument.Load(stream, FormatType.Docx);
86+
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
87+
document.Dispose();
88+
stream.Close();
89+
return json;
90+
}
91+
```
92+
93+
* Open the `appsettings.json` file in your web service project, Add the following lines below the existing `"AllowedHosts"` configuration
94+
95+
```json
96+
{
97+
"Logging": {
98+
"LogLevel": {
99+
"Default": "Information",
100+
"Microsoft.AspNetCore": "Warning"
101+
}
102+
},
103+
"AllowedHosts": "*",
104+
"AccessKey": "Your Access Key from AWS S3",
105+
"SecretKey": "Your Secret Key from AWS S3",
106+
"BucketName": "Your Bucket name from AWS S3"
107+
}
108+
```
109+
110+
N> Replace **Your Access Key from AWS S3**, **Your Secret Key from AWS S3**, and **Your Bucket name from AWS S3** with your actual AWS access key, secret key and bucket name
111+
112+
**Step 3:** Modify the Index.cshtml File in the Document Editor sample
113+
114+
In the client-side, the document is returned from the web service is opening using [`open`](../../api/document-editor/#open) method.
115+
116+
{% tabs %}
117+
{% highlight cshtml tabtitle="CSHTML" %}
118+
{% include code-snippet/document-editor-container/open-aws-s3/tagHelper %}
119+
{% endhighlight %}
120+
{% highlight c# tabtitle="Document-editor.cs" %}
121+
{% include code-snippet/document-editor-container/open-aws-s3/document-editor.cs %}
122+
{% endhighlight %}
123+
{% endtabs %}
124+
125+
126+
127+
N> The **AWSSDK.S3** NuGet package must be installed in your application to use the previous code example.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
layout: post
3+
title: Open Azure Blob Files in ASP.NET Core Document editor | Syncfusion
4+
description: Learn about how to Open document from Azure Blob Storage in ASP.NET Core Document editor control of Syncfusion Essential JS 2 and more details.
5+
platform: document-processing
6+
control: Open document from Azure Blob Storage
7+
documentation: ug
8+
domainurl: ##DomainURL##
9+
---
10+
11+
# Open document from Azure Blob Storage
12+
13+
To load document from Azure Blob Storage in a Document Editor, you can follow the steps below
14+
15+
16+
**Step 1:** Create a Simple Document Editor Sample in ASP.NET Core
17+
18+
Start by following the steps provided in this [link](../../document-editor/getting-started-core) to create a simple Document Editor sample in ASP.NET Core. This will give you a basic setup of the Document Editor component.
19+
20+
21+
**Step 2:** Modify the `DocumentEditorController.cs` File in the Web Service Project
22+
23+
* Open the `DocumentEditorController.cs` file in your web service project.
24+
25+
* Import the required namespaces at the top of the file:
26+
27+
```csharp
28+
using System.IO;
29+
using Azure.Storage.Blobs;
30+
using Azure.Storage.Blobs.Specialized;
31+
```
32+
33+
* Add the following private fields and constructor parameters to the `DocumentEditorController` class, In the constructor, assign the values from the configuration to the corresponding fields
34+
35+
36+
```csharp
37+
private readonly string _storageConnectionString;
38+
private readonly string _storageContainerName;
39+
private readonly ILogger<DocumentEditorController> _logger;
40+
41+
public DocumentEditorController(IConfiguration configuration, ILogger<DocumentEditorController> logger)
42+
{
43+
_storageConnectionString = configuration.GetValue<string>("connectionString");
44+
_storageContainerName = configuration.GetValue<string>("containerName");
45+
_logger = logger;
46+
}
47+
```
48+
49+
* Modify the `LoadFromAzure()` method to load the document from Azure Blob Storage
50+
51+
```csharp
52+
53+
[HttpPost("LoadFromAzure")]
54+
[Microsoft.AspNetCore.Cors.EnableCors("MyPolicy")]
55+
[Route("[controller]/LoadFromAzure")]
56+
//Post action for Loading the PDF documents 
57+
 
58+
public IActionResult LoadFromAzure([FromBody] Dictionary<string, string> jsonObject)
59+
{
60+
MemoryStream stream = new MemoryStream();
61+
62+
if (jsonObject == null && !jsonObject.ContainsKey("documentName"))
63+
{
64+
return null
65+
}
66+
BlobServiceClient blobServiceClient = new BlobServiceClient(_storageConnectionString);
67+
string fileName = jsonObject["documentName"];
68+
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(_storageContainerName);
69+
BlockBlobClient blockBlobClient = containerClient.GetBlockBlobClient(fileName);
70+
blockBlobClient.DownloadTo(stream);
71+
WordDocument document = WordDocument.Load(stream, FormatType.Docx);
72+
string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
73+
document.Dispose();
74+
stream.Close();
75+
return json;
76+
}
77+
```
78+
79+
* Open the `appsettings.json` file in your web service project, Add the following lines below the existing `"AllowedHosts"` configuration
80+
81+
```json
82+
{
83+
"Logging": {
84+
"LogLevel": {
85+
"Default": "Information",
86+
"Microsoft.AspNetCore": "Warning"
87+
}
88+
},
89+
"AllowedHosts": "*",
90+
"connectionString": "*Your Connection string from Azure*",
91+
"containerName": "*Your container name in Azure*"
92+
}
93+
```
94+
95+
N> Replace **Your Connection string from Azure** with the actual connection string for your Azure Blob Storage account and **Your container name in Azure** with the actual container name
96+
97+
**Step 3:** Modify the Index.cshtml File in the Document Editor sample
98+
99+
In the client-side, the document is returned from the web service is opening using [`open`](../../api/document-editor/#open) method.
100+
101+
102+
{% tabs %}
103+
{% highlight razor tabtitle="CSHTML" %}
104+
{% include code-snippet/document-editor-container/open-azure-blob/razor %}
105+
{% endhighlight %}
106+
{% highlight c# tabtitle="Document-editor.cs" %}
107+
{% include code-snippet/document-editor-container/open-azure-blob/document-editor.cs %}
108+
{% endhighlight %}
109+
{% endtabs %}
110+
{% endif %}
111+
112+
N> The **Azure.Storage.Blobs** NuGet package must be installed in your application to use the previous code example.

0 commit comments

Comments
 (0)