Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Words on Windows Azure provides an ability to load, convert, and save documents. For this purpose, you can create an application that:
The application described in this article is implemented as WebRole and can be run in the Development Fabric (on the developer’s machine) or deployed to Windows Azure. This application is one of the possible examples of how Aspose.Words works in the cloud.
This section discusses a basic project that does not use advanced Aspose.Words features or sophisticated services of the Windows Azure platform.
The project demonstrates how Aspose.Words can be easily used to build applications running in the cloud.
To create the application, you need to perform the following steps:
NuGet
reference to Aspose.Words.The actual code to convert a document using Aspose.Words consists of only two lines, which create a new Document object to load the document, and then call the Save method with the desired format. The following code example shows how to convert a document in Windows Azure:
.NET
using Aspose.Words;
using Aspose.Words.Saving;
using System.Web;
using System;
using System.IO;
namespace WebRole
{
/// <summary>
/// This demo shows how to use Aspose.Words for .NET inside a `WebRole` in a simple
/// Windows Azure application. There is just one ASP.NET page that provides a user
/// interface to convert a document from one format to another.
/// </summary>
public partial class _Default : System.Web.UI.Page
{
protected void SubmitButton_Click(object sender, EventArgs e)
{
HttpPostedFile postedFile = SrcFileUpload.PostedFile;
if (postedFile.ContentLength == 0)
throw new Exception("There was no document uploaded.");
if (postedFile.ContentLength > 512 * 1024)
throw new Exception("The uploaded document is too big. This demo limits the file size to 512Kb.");
// Create a suitable file name for the converted document.
string dstExtension = DstFormatDropDownList.SelectedValue;
string dstFileName = Path.GetFileName(postedFile.FileName) + "_Converted." + dstExtension;
SaveFormat dstFormat = FileFormatUtil.ExtensionToSaveFormat(dstExtension);
// Convert the document and send to the browser.
Document doc = new Document(postedFile.InputStream);
doc.Save(Response, dstFileName, ContentDisposition.Inline, SaveOptions.CreateSaveOptions(dstFormat));
// Required. Otherwise DOCX cannot be opened on the client (probably not all data sent
// or some extra data sent in the response).
Response.End();
}
static _Default()
{
// Uncomment this code and embed your license file as a resource in this project and this code
// will find and activate the license. Aspose.Wods licensing needs to execute only once
// before any Document instance is created and a static ctor is a good place.
//
// Aspose.Words.License l = new Aspose.Words.License();
// l.SetLicense("Aspose.Words.lic");
}
}
}
To test and run the example project, perform the following steps:
WebRole
project the Start Up project in the solution and run. Visual Studio will open a browser window and load the form into it. You can upload a sample document and verify that the conversion is working.CloudService
project and make it the Start Up project for the solution and run. This time, it may take a bit longer to build the application because Visual Studio starts up the Development Fabric and deploys your project into it. The browser window will open with the form again, and you will be able to test the application.URL
to the deployed application.The following picture shows the Web Role project running in the Microsoft Azure cloud:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.