protected override WebControl CreateEditModeControlCore() { //var panel = new ASPxPanel(); //var ribbon = new ASPxRibbon(); //ribbon.ID = "SpreadSheetRibbon"; this._spreadsheet = new ASPxSpreadsheet(); _spreadsheet.SettingsDocumentSelector.UploadSettings.Enabled = true; _spreadsheet.SettingsDocumentSelector.UploadSettings.UseAdvancedUploadMode = true; _spreadsheet.SettingsDocumentSelector.UploadSettings.AdvancedModeSettings.EnableFileList = true; _spreadsheet.SettingsDocumentSelector.UploadSettings.AdvancedModeSettings.EnableMultiSelect = true; _spreadsheet.ShowConfirmOnLosingChanges = false; _spreadsheet.ClientSideEvents.Init = "function(s, e){ s.SetFullscreenMode(true); }"; _spreadsheet.Height = 800; _spreadsheet.CreateDefaultRibbonTabs(true); _spreadsheet.Load += _spreadsheet_Load; var t = _spreadsheet.RibbonTabs.Add("数据导入"); var g = t.Groups.Add("导入"); var temp = new RibbonTemplateItem(); g.Items.Add(temp); StartImport = new StartImportTemplate(_spreadsheet); StartImport.Execute += StartImport_Execute; temp.Template = StartImport; return(_spreadsheet); }
protected override void Dispose(bool disposing) { if (disposing) { if (_spreadsheet != null) { _spreadsheet.Load -= _spreadsheet_Load; } _spreadsheet = null; } base.Dispose(disposing); }
protected void pageControlDetails_Load(object sender, EventArgs e) { if (Session["fileNameToDownload"] != null) { string fileURL = Session["fileNameToDownload"].ToString().Split('|')[0]; string FileExtn = Session["fileNameToDownload"].ToString().Split('|')[1]; string fileName = Session["fileNameToDownload"].ToString().Split('|')[2]; string storageFileName = Session["fileNameToDownload"].ToString().Split('|')[3]; ASPxPageControl pageControlDetails = (ASPxPageControl)sender; //HtmlGenericControl documentDownloadLink = (HtmlGenericControl)pageControlDetails.FindControl("previewNotAvailableText"); //documentDownloadLink.Visible = true; //documentDownloadLink.InnerHtml = "<a href=\"" + fileURL + "\" download=\"" + fileName + "\">Download File</a>"; if (FileExtn == ".txt") { ASPxRichEdit richEditPreview = (ASPxRichEdit)pageControlDetails.FindControl("richDetailsPreview"); richEditPreview.Visible = true; //richEditPreview.Open(Path.GetTempPath() + "\\" + fileURL); richEditPreview.Open(Guid.NewGuid().ToString(), DevExpress.XtraRichEdit.DocumentFormat.PlainText, () => { byte[] fileData = null; using (var wc = new System.Net.WebClient()) fileData = wc.DownloadData(fileURL); return(new MemoryStream(fileData)); }); } else if (FileExtn == ".doc") { ASPxRichEdit richEditPreview = (ASPxRichEdit)pageControlDetails.FindControl("richDetailsPreview"); richEditPreview.Visible = true; //richEditPreview.Open(Path.GetTempPath() + "\\" + fileURL); richEditPreview.Open(Guid.NewGuid().ToString(), DevExpress.XtraRichEdit.DocumentFormat.Doc, () => { byte[] fileData = null; using (var wc = new System.Net.WebClient()) fileData = wc.DownloadData(fileURL); return(new MemoryStream(fileData)); }); } else if (FileExtn == ".docx") { ASPxRichEdit richEditPreview = (ASPxRichEdit)pageControlDetails.FindControl("richDetailsPreview"); richEditPreview.Visible = true; //richEditPreview.Open(Path.GetTempPath() + "\\" + fileURL); richEditPreview.Open(Guid.NewGuid().ToString(), DevExpress.XtraRichEdit.DocumentFormat.OpenXml, () => { byte[] fileData = null; using (var wc = new System.Net.WebClient()) fileData = wc.DownloadData(fileURL); return(new MemoryStream(fileData)); }); } else if (FileExtn == ".xls") { DevExpress.Web.ASPxSpreadsheet.ASPxSpreadsheet spreadSheetPreview = (ASPxSpreadsheet)pageControlDetails.FindControl("spreadSheetPreview"); spreadSheetPreview.Visible = true; MemoryStream stream = new MemoryStream(); spreadSheetPreview.Open(Guid.NewGuid().ToString(), DevExpress.Spreadsheet.DocumentFormat.Xls, () => { byte[] fileData = null; using (var wc = new System.Net.WebClient()) fileData = wc.DownloadData(fileURL); return(new MemoryStream(fileData)); }); //spreadSheetPreview. } else if (FileExtn == ".xlsx") { DevExpress.Web.ASPxSpreadsheet.ASPxSpreadsheet spreadSheetPreview = (ASPxSpreadsheet)pageControlDetails.FindControl("spreadSheetPreview"); spreadSheetPreview.Visible = true; MemoryStream stream = new MemoryStream(); spreadSheetPreview.Open(Guid.NewGuid().ToString(), DevExpress.Spreadsheet.DocumentFormat.Xlsx, () => { byte[] fileData = null; using (var wc = new System.Net.WebClient()) fileData = wc.DownloadData(fileURL); return(new MemoryStream(fileData)); }); //spreadSheetPreview. } else if (FileExtn == ".pdf") { HtmlGenericControl pdfPreview = (HtmlGenericControl)pageControlDetails.FindControl("pdfPreview"); pdfPreview.Visible = true; using (var client = new System.Net.WebClient()) { client.DownloadFile(fileURL, Server.MapPath("~/TempFiles") + "/" + fileName); } //pdfPreview.InnerHtml = "<embed src = \""+ Path.GetTempPath() + "\\" + fileURL+"\" />"; pdfPreview.InnerHtml = "<iframe src=\"" + "../TempFiles" + "/" + fileName + "\" style = \"width:100%; height:500px;\" frameborder = \"0\" ></iframe> "; //pdfPreview.InnerHtml = "<iframe src = \"" + fileURL + "\" style = \"width:600px; height:500px;\" frameborder = \"0\"></iframe>"; } else if (FileExtn == ".jpg" || FileExtn == ".jpeg") { HtmlGenericControl imgPreview = (HtmlGenericControl)pageControlDetails.FindControl("pdfPreview"); imgPreview.Visible = true; imgPreview.InnerHtml = "<img class=\"preview\" src = \"" + fileURL + "\">"; } else { HtmlGenericControl previewNotAvailableText = (HtmlGenericControl)pageControlDetails.FindControl("documentDownloadLink"); previewNotAvailableText.Visible = true; previewNotAvailableText.InnerHtml = "<h1>Preview Not Available</h1>"; } } }