We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Mail Merge to Documents in Blob Storage : Possible?

Hi Team,


I want to refer to a document(s) in azure blob storage and perform. some operations like mail-merge etc. and generate the Result file(s) to another Folder in the same blob storage using C#.

Also Merge the document in the Result Folder at the End.


I have done this locally by using folders in disk,but is this can be done with the folders in blob storage


Is this possible? without downloading file to local folder?


2 Replies

AN Anto Nihil Sahaya Raj Syncfusion Team May 3, 2023 05:43 PM UTC

Hi Sandeep,

Currently, we are checking your requirement. We will share the details tomorrow 4th May 2023.

Regards,
Anto Nihil S



SB Suriya Balamurugan Syncfusion Team May 4, 2023 07:00 AM UTC

Hi Sandeep,

From the given details, we have found that your
requirement is to download the Word document from Azure blob storage to perform some operations like mail merge or merge Word documents. Then upload the saved Word document to Azure blob storage.

Syncfusion Word (DocIO) library has API’s to load and save the Word document as a stream. Please refer the below UG documentation links to know about this,
https://help.syncfusion.com/file-formats/docio/loading-and-saving-document#opening-an-existing-document-from-stream
https://help.syncfusion.com/file-formats/docio/loading-and-saving-document#saving-a-word-document-to-stream

To achieve your requirement, we suggest you to download the Word document as a stream from the Azure blob storage and perform any manipulation in the Word document. Then upload the saved Word document stream to Azure blob storage.

To download and upload a file to Azure Blob Storage in C#, you can use the Azure.Storage.Blobs package provided by Microsoft or else you can use any approach to download and upload a file as stream in blob storage to work with our DocIO library. Please refer the below code snippet to download and upload Word document as stream in Azure blob storage,

using Azure.Storage.Blobs;

using System.IO;

using Syncfusion.DocIO;

using Syncfusion.DocIO.DLS;

 

// Replace these values with your own

string connectionString = "<your_connection_string>";

string containerName = "<your_container_name>";

string blobName = "<your_blob_name>";

 

// Create a BlobServiceClient object using the connection string

BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

 

// Get a reference to the blob container

BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

 

// Get a reference to the blob

BlobClient blobClient = containerClient.GetBlobClient(blobName);

 

// Download the blob as a stream

var response = await blobClient.DownloadAsync();

Stream stream = response.Value.Content;

 

// Open the Word document using stream

using (WordDocument document = new WordDocument(stream, Syncfusion.DocIO.FormatType.Automatic))

{

    //Do manipulation.

    //Perform any operation.

 

    //Save the Word document as memory stream.

    using (MemoryStream memoryStream = new MemoryStream())

    {

        document.Save(memoryStream, Syncfusion.DocIO.FormatType.Docx);

        //Upload the MemoryStream to the blob.

        await blobClient.UploadAsync(memoryStream);

    }

}


Also refer our documentation link to know more about download files from azure blob storage,
https://www.syncfusion.com/blogs/post/download-files-from-azure-blob-storage-with-blazor-webassembly-and-asp-net-web-api.aspx

If this post is helpful, please consider accepting it as the solution so that other members can locate it more quickly.

Regards,
Suriya Balamurugan.


Loader.
Up arrow icon