Skip to content

Latest commit

 

History

History
63 lines (46 loc) · 4.17 KB

File metadata and controls

63 lines (46 loc) · 4.17 KB

File Manager for ASP.NET Web Forms - How to open a selected text or spreadsheet file

This example demonstrates how to open a selected file in the ASPxSpreadsheet or ASPxRichEdit component.

Implementation Details

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));
}

Files to Review

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)