This section describes how to use Aspose.Editor in an ASP.NET application to achieve WYSIWIG word processing in the browser.
When Aspose.Editor.Client executes in Microsoft Internet Explorer, it is able to receive documents from the server, render word processing user interface for editing right on the web page, and save documents back to server.
Aspose.Editor.Server executes in an ASP.NET application and is responsible for reading documents in all supported formats and sending them to Aspose.Editor.Client, as well as receiving documents from the client and storing them in all supported formats.
Aspose.Editor.Client.EditorControl is a Windows Forms control and Aspose.Editor.Server.EditorControl is an ASP.NET control, they have been designed to be used together in an ASP.NET application.
Before you begin
The information in this section assumes you are familiar with .NET development and ASP.NET technology. It primarily focuses on development aspects specific to using Aspose.Editor word processing controls. If you need basic information on .NET or ASP.NET, please visit Microsoft MSDN.
Step 1. Create an ASP.NET Project
Note: If you already have an ASP.NET project you want to use, then skip this step.
In Microsoft Visual Studio, go to the File -> New -> Project menu and select ASP.NET Web Application project from the dialog.
Specify application location URL. If you have IIS installed and running, a new ASP.NET Web Application project will be created in the specified location. Check through the generated code. Here is what you should see:
Step 2. Prepare Site Directory
At this step you need to design the directory structure of you web application and setup security policy.
First, decide where Aspose.Editor.Client.dll will be located on the server, here is why this is important:
- The Server control must know location of Aspose.Editor.Client.dll since it will generate <object> tag for it and must reference correct dll, so the browser can request it using correct URL later.
- The directory which contains Aspose.Editor.Client.dll must have execution permissions configured to Scripts Only. You can configure it from the IIS configuration wizard.
Note: Never place Aspose.Editor.Client.dll in the application binary folder (default "bin" folder) since that folder is inaccessible to the browser.
For the purpose of this example, create the ClientBin folder in the site root and then copy C:\Program Files\Aspose\Aspose.Editor\Bin\Aspose.Editor.Client.dll into the ClientBin folder.
Make sure the execution permission for the ClientBin folder is set to "Scripts Only" in the IIS directory properties. Here is the correct value in the IIS property page:
Now we must reference the client control from the application configuration file Web.config. When the server control renders a web page, it looks for the client control setting that is specified in the application configuration file.
Here is how we do that:
- Open Web.config file in any text editor, e.g. Notepad.
- Under the <configuration> tag insert the following lines:
<appSettings>
<add key="Aspose.Editor.Client.ClassId" value="ClientBin/Aspose.Editor.Client.dll#Aspose.Editor.Client.EditorControl"/>
</appSettings>
- Save the file.
The setting specifies part of the <object> tag embedded into the page. Actual value is the concatenation of the "http:/<your app site root>" and the specified value.
Step 3. Configure Security
Next, we must make sure Internet Explorer will grant appropriate permissions for the client control when it is activated on the page. In general, security is a separate topic to discuss, but for the purpose of this example we'll use a simple scenario.
We assume that the server and the browser are running on the same machine, and thus the site address in Internet Explorer looks like "http://localhost/...". We also assume that the Integrated Windows Authentication is used to access site resources. You can check IIS settings of the site, it should look like this:
Here is what we are trying to accomplish. We need to grant FullTrust security level to the code originating from the URL of our site. In order to do this we will use the caspol.exe (more info) utility which ships with the .NET Framework.
Note: Each .NET version installed uses its own security policy, so we must go to the appropriate folder which contains the .NET Framework used by Internet Explorer and invoke caspol.exe from there. Internet Explorer uses latest installed .NET Runtime version by default, however this can be overridden in iexplore.exe.config file.
Go to the appropriate "C:\WINDOWS\Microsoft.NET\Framework\<Framework version>\" folder and execute the following at the command line:
caspol.exe -polchgprompt off -q -machine -addgroup 1. -url http://localhost/WebApplication1/* FullTrust -description "Full trust rule for the Aspose.Editor client control"
You can now check if policy has been changed with this command:
caspol.exe –listgroups
If you see "Url - http://localhost/WebApplication1/*: FullTrust" in the list, then you are OK to continue.
Note: Depending on you current settings, you may have to configure Internet Explorer as well. Java Scripts and ActiveX must be enabled, otherwise client control will fail to activate. Additionally, if you want to access session state variables when handling client-server document exchanges you must enable cookies.
Step 4. Design a Page with the Control
Open WebControl1.aspx.cs in the designer. Using the property sheet, change the pageLayout property of the DOCUMENT object to FlowLayout. This will allow easier positioning of controls. Then locate the server EditorControl on the toolbox (Aspose.Editor.Server tab) and drag it onto the design surface. Change the Height and the Width properties of EditorControl1 to 100%.

Add two HTML buttons under the control and name them Send and Receive correspondingly, here is what you will see:
We have two buttons which trigger sending and receiving, now we will write script which actually does that.
Switch to HTML view and do the following:
- Find <INPUT type="button" value="Send"> and change it to
<INPUT type="button" value="Send" onclick="SendDocument()">
- Find <INPUT type="button" value="Receive"> and change it to
<INPUT type="button" value="Receive" onclick="ReceiveDocument()">
- Find <body> and change it to
<body onload = "OnLoad()">
- At the bottom of the page add this script block:
<script type="text/JavaScript">
function SendDocument()
{
control = document.getElementById('EditorControl1');
control.Send("MyFile.doc");
control.focus();
}
function ReceiveDocument()
{
control = document.getElementById('EditorControl1');
control.Receive("MyFile.doc");
control.focus();
}
function OnLoad()
{
control = document.getElementById('EditorControl1');
control.Open();
control.focus();
}
</script>
This is enough for now, the page is ready.
Step 5. Implement Server-Side Events
After your page is complete it is time to write server code responsible for exchanging the document with the client. For this example, we will simply save the document as a disk file when it is received by the server and send it back to a client when it is requested.
First, add the following line at the top of WebForm1.aspx.cs:
using Aspose.Editor.Server;
Then add this code as a first line in the Page_Load, it will analyze incoming requests and generate document events for us:
EditorControl1.OnPageLoad();
Now, in the designer use the properties window and get to the events tab of the server control. Double click the DocumentReceived and DocumentRequested events. Here is what you will see:
Next, in WebForm1.aspx.cs scroll to the event handling methods designer has just been generated:
private void EditorControl1_DocumentReceived(object sender, DocumentEventArgs e)
{
}
private void EditorControl1_DocumentRequested(object sender, DocumentEventArgs e)
{
}
You now have empty event handlers in place, let's add some code to them. Add this code to the EditorControl1_DocumentReceived method:
// Create the file were we will save the document to.
// Make sure your ASPNET account has enough permissions in this folder.
Stream stream = File.Create(@”C:\” + e.Param);
// This extracts the document received by the server into a stream in the DOC format.
e.GetDocument(stream, DocumentFormat.Doc);
// Close the file.
stream.Close();
In the EditorControl1_DocumentRequested add this code:
// Open the file containing the document we want to send to the client.
Stream stream = File.OpenRead(@”C:\” + e.Param);
// This copies the document into the response that will be sent to the client.
e.SetDocument(stream);
// Close the original stream.
stream.Close();
That’s it. Our simple application is ready to run. It will receive and store document on the server and send it back to the client upon request.
Step 6. Run Your Application
Compile and run the application. Internet Explorer will show up and when the page loads completely you'll see the following:
Type some text in the document and click the Send button. Your document will be sent to the server and saved at the server at the path "C:\MyFile.doc".
Type more text. Now click the Receive button. You will see that the last entered text has disappeared, this is because the document (that has just been saved) was received from the server and opened in the browser.
Conclusion
This simple ASP.NET Web application has demonstrated common development steps required to build a word processor enabled ASP.NET Web application using Aspose.Editor controls.
This example might not look much because it just stores the document into the same file on the server, but it shows that the logic how to load and store documents on the server is completely in your hands. You can store documents on the server in any way you want: into disk files, into binary fields in a database or even into a Microsoft SharePoint repository.
For more information, please look through the API Reference for the Aspose.Editor.Client and Aspose.Editor.Server namespaces.
What if the control doesn't show
There can be three main reasons why the page loads successfully but the control doesn't show.
- If the control frame is drawn and there is an icon
in the left upper corner, or the frame is empty with disabled scroll bar to the right of it, most likely reason is that the page requested Aspose.Editor.Client.dll using an invalid URL.
To correct, check the source of the page. From the context menu click "View Source". In the page look for the <object id="EditorControl1"… > tag. Make sure that classid equals "http:ClientBin\Aspose.Editor.Client.dll#Aspose.Editor.Client.EditorControl". If it is not, check the Web.config file for appropriate setting. If the classid is correct, then either Aspose.Editor.Client.dll is missing from ClientBin or IIS cannot access the file due to security restrictions. Make sure that both IIS rights and credentials allow reading from the ClientBin directory.
- ClientBin directory has execution permissions set to scripts and executables or authentication at web server resulted in insufficient permission to access ClientBin directory. In this case you will most likely see an empty frame with disabled scrollbar to the right of it, or receive HTTP error 403 "Forbidden", or page will not load at all.
Go to the IIS settings and change execution permissions to Scripts Only. Then check that Integrated Windows Authentication is used.
- Internet Explorer settings or security policy do no allow activation of the control. This is the most common reason because setting security policy may be tricky in particular cases. If you see empty frame with picture icon
in the upper left corner, then incorrect security settings are the most likely reason for the activation failure.
First of all, enable internet explorer debug log, see http://support.microsoft.com/kb/313892 for details. In the log you should see if control activation was attempted and what was the reason for the failure. If security exception is the reason then either security policy or Internet Explorer security settings cause this problem. Try to find why appropriate trust is not given to the control, unfortunately, there is no "one for all" solution. Consult your system administrator or post in the Aspose forums if you are unable to resolve the issue.
What if the document doesn't get saved on the server
There can be several reasons why the document is not saved on server, here are some of them:
- You do not call OnPageLoad method of the server control as a first statement in the Page_Load method of the page. Events will not fire if you don't.
- You are not handling OnDocumentReceived event. Server doesn't have default logic for saving the document instead it will do nothing to store it.
- Your web site is configured to serve "friendly" error messages to the client. In this case if error happens on the server while document is saved then client will receive 200 OK responses instead, client will assume than document has been saved successfully and obviously you'll have no clue as to why nothing happens on the server.
What if after control or plugins are updated on the server clients still use older version
Caching and load contexts are the main reasons for this behavior.
- During development use "gacutil /cdl" to clear download assembly cache. In production this is not an option. Just make sure that when files on the web server are updated (including client dll) their date/time attributes are set to the greater values than original files have.
- If you are building plugin modules for the editor make sure version of the assembly is increased after each build. Don't hardcode version. If two assemblies have different bits but same strong name you may have caching issues.
- If you still can't resolve this issue, please clear all cached instances of the DLL which cause troubles, including Internet Explorer cache, Download assembly cache, Visual Studio cache, ASP.NET cache. Consult Microsoft site for additional information.
You can always enable Fusion Log to see which particular DLL gets loaded when binding of the assembly occurs.