This example demonstrates how to open a selected file in the ASPxSpreadsheet or ASPxRichEdit component.
In this example, ASPxFileManager contains files that can be opened in the ASPxSpreadsheet or ASPxRichEdit component. When a user clicks a file, the ASPxClientFileManager.SelectedFileChanged event fires. The event handler shows a popup and sends a callback to the server.
function OnSelectedFileChanged(s, e) {
if (e.file != null) {
PopupWithDocument.Show();
PopupWithDocument.PerformCallback(e.file.GetFullName());
}
}
On the server, the WindowCallback event handler determines the format of the selected file and opens the file in the ASPxSpreadsheet component if it is a spreadsheet format; otherwise the document is opened in the ASPxRichEdit component.
protected void PopupWithDocument_WindowCallback(object source, DevExpress.Web.PopupWindowCallbackArgs e) {
String fullFileName = e.Parameter;
object format = DocumentFormatHelper.GetFormat(fullFileName);
if (format == null) return;
Boolean isSpreadsheet = format is DevExpress.Spreadsheet.DocumentFormat;
ASPxSpreadsheet1.Visible = isSpreadsheet;
ASPxRichEdit1.Visible = !isSpreadsheet;
var docId = Guid.NewGuid().ToString();
var docPath = Server.MapPath(fullFileName);
if (isSpreadsheet)
ASPxSpreadsheet1.Open(docId, (DevExpress.Spreadsheet.DocumentFormat)format, () => File.ReadAllBytes(docPath));
else
ASPxRichEdit1.Open(docId, (DevExpress.XtraRichEdit.DocumentFormat)format, () => File.ReadAllBytes(docPath));
}
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)