Occurs when server EditorControl receives a request for a document from the client.
Event Data
The event handler receives an argument of type DocumentEventArgs containing data related to this event. The following DocumentEventArgs property provides information specific to this event.
| Property | Description |
|---|
| Param | Gets or sets a custom string parameter passed to/from the client. |
Remarks
The server page must implement this event handler in order to be able to send documents to the client. Inside the event handler, use the SetDocument method to specify which document must be sent to the client.
If you do not implement this event handler, or if you don't specify a document using SetDocument, the client will receive an HTTP error in response.
Example
Shows possible implementation of DocumentRequested event handler. Document is read from the DOC file and sent to the client.
[C#]
private void OnDocumentRequested(object sender, DocumentEventArgs e)
{
// Passed param value is treated as file name, here we map it to server path
string fileName = MapPath("Documents\\" + e.Param);
Debug.WriteLine("Sending file " + fileName);
// Check if requested file exists
// We throw exception which is caught by control code and transferred to client
if ( !File.Exists(fileName) )
throw new FileNotFoundException("fileName");
// Open document for reading. If format is not recognized exception is thrown.
FileStream stream = File.OpenRead(fileName);
// Pass document stream to server control
e.SetDocument(stream);
stream.Close();
}
[Visual Basic]
Private Sub OnDocumentRequested(ByVal sender As Object, ByVal e As DocumentEventArgs)
' Passed param value is treated as file name, here we map it to server path
Dim fileName As String = MapPath("Documents\" & e.Param)
Debug.WriteLine("Sending file " & fileName)
' Check if requested file exists
' We throw exception which is caught by control code and transferred to client
If (Not File.Exists(fileName)) Then
Throw New FileNotFoundException("fileName")
End If
' Open document for reading. If format is not recognized exception is thrown.
Dim stream As FileStream = File.OpenRead(fileName)
' Pass document stream to server control
e.SetDocument(stream)
stream.Close()
End SubSee Also
EditorControl Class | Aspose.Editor.Server Namespace | DocumentReceived