Skip to content

Commit e0a398b

Browse files
Merge pull request #2071 from syncfusion-content/1000615-openD
1000615: Visible the storage document in core and MVC document editor
2 parents 171a228 + e89b8d6 commit e0a398b

29 files changed

Lines changed: 1997 additions & 34 deletions

Document-Processing-toc.html

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,8 +2871,30 @@
28712871
<li><a href="/document-processing/word/word-processor/asp-net-core/overview">Overview</a></li>
28722872
<li><a href="/document-processing/word/word-processor/asp-net-core/getting-started-core">Getting Started</a></li>
28732873
<li><a href="/document-processing/word/word-processor/asp-net-core/feature-module">Feature modules</a></li>
2874-
<li><a href="/document-processing/word/word-processor/asp-net-core/import">Import</a></li>
2875-
<li><a href="/document-processing/word/word-processor/asp-net-core/export">Export</a></li>
2874+
<li>
2875+
<a href="/document-processing/word/word-processor/asp-net-core/import">Opening Document</a>
2876+
<ul>
2877+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/azure-blob-storage">From Microsoft Azure Blob Storage</a></li>
2878+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/aws-s3-bucket">From AWS S3</a></li>
2879+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/box-cloud-file-storage">From Box cloud file storage</a></li>
2880+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/dropbox-cloud-file-storage">From Dropbox cloud file storage</a></li>
2881+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/google-cloud-storage">From Google Cloud Storage</a></li>
2882+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/google-drive">From Google Drive</a></li>
2883+
<li><a href="/document-processing/word/word-processor/asp-net-core/opening-documents/one-drive">From One Drive</a></li>
2884+
</ul>
2885+
</li>
2886+
<li>
2887+
<a href="/document-processing/word/word-processor/asp-net-core/export">Saving Document</a>
2888+
<ul>
2889+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/azure-blob-storage">To Microsoft Azure Blob Storage</a></li>
2890+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/aws-s3-bucket">To AWS S3</a></li>
2891+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/box-cloud-file-storage">To Box cloud file storage</a></li>
2892+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/dropbox-cloud-file-storage">To Dropbox cloud file storage</a></li>
2893+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/google-cloud-storage">To Google Cloud Storage</a></li>
2894+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/google-drive">To Google Drive</a></li>
2895+
<li><a href="/document-processing/word/word-processor/asp-net-core/saving-documents/one-drive">To One Drive</a></li>
2896+
</ul>
2897+
</li>
28762898
<li><a href="/document-processing/word/word-processor/asp-net-core/collaborative-editing/overview">Collaborative Editing</a>
28772899
<ul>
28782900
<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>
@@ -2976,7 +2998,18 @@
29762998
<li><a href="/document-processing/word/word-processor/asp-net-mvc/opening-documents/one-drive">From One Drive</a></li>
29772999
</ul>
29783000
</li>
2979-
<li><a href="/document-processing/word/word-processor/asp-net-mvc/export">Export</a></li>
3001+
<li>
3002+
<a href="/document-processing/word/word-processor/asp-net-mvc/export">Saving Document</a>
3003+
<ul>
3004+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/azure-blob-storage">To Microsoft Azure Blob Storage</a></li>
3005+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/aws-s3-bucket">To AWS S3</a></li>
3006+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/box-cloud-file-storage">To Box cloud file storage</a></li>
3007+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/dropbox-cloud-file-storage">To Dropbox cloud file storage</a></li>
3008+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/google-cloud-storage">To Google Cloud Storage</a></li>
3009+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/google-drive">To Google Drive</a></li>
3010+
<li><a href="/document-processing/word/word-processor/asp-net-mvc/saving-documents/one-drive">To One Drive</a></li>
3011+
</ul>
3012+
</li>
29803013
<li><a href="/document-processing/word/word-processor/asp-net-mvc/collaborative-editing/overview">Collaborative Editing</a>
29813014
<ul>
29823015
<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` method.
115+
116+
{% tabs %}
117+
{% highlight cshtml tabtitle="CSHTML" %}
118+
{% include code-snippet/document-editor/asp-net-core/document-editor-container/open-aws-s3/tagHelper %}
119+
{% endhighlight %}
120+
{% highlight c# tabtitle="Document-editor.cs" %}
121+
{% include code-snippet/document-editor/asp-net-core/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: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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` method.
100+
101+
102+
{% tabs %}
103+
{% highlight razor tabtitle="CSHTML" %}
104+
{% include code-snippet/document-editor/asp-net-core/document-editor-container/open-azure-blob/razor %}
105+
{% endhighlight %}
106+
{% highlight c# tabtitle="Document-editor.cs" %}
107+
{% include code-snippet/document-editor/asp-net-core/document-editor-container/open-azure-blob/document-editor.cs %}
108+
{% endhighlight %}
109+
{% endtabs %}
110+
111+
N> The **Azure.Storage.Blobs** NuGet package must be installed in your application to use the previous code example.

0 commit comments

Comments
 (0)