This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
Default.aspx.cs
60 lines (56 loc) · 2.32 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using DevExpress.Spreadsheet;
using DevExpress.Web.ASPxSpreadsheet;
using DevExpress.Web.Office;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DXSample {
public partial class Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
string SessionKey = "EditedDocuemntID";
int MAX_LENGTH = 1000000;
protected string EditedDocuemntID {
get { return (string)Session[SessionKey] ?? string.Empty; }
set { Session[SessionKey] = value; }
}
protected void Page_Init(object sender, EventArgs e) {
if (!IsPostBack && !IsCallback) {
if (!string.IsNullOrEmpty(EditedDocuemntID)) {
DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocuemntID).DocumentId);
EditedDocuemntID = string.Empty;
}
EditedDocuemntID = Guid.NewGuid().ToString();
DataView view = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
Spreadsheet.Open(
EditedDocuemntID,
DocumentFormat.Xlsx,
() => { return (byte[])view.Table.Rows[0]["DocumentContent"]; }
);
}
}
protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e) {
e.Command.Parameters["@DocumentID"].Value = 1; // First Row
byte[] docBytes = Spreadsheet.SaveCopy(DocumentFormat.Xlsx);
if (docBytes.Length <= MAX_LENGTH)
e.Command.Parameters["@DocumentContent"].Value = docBytes;
else
throw new Exception("The file exceeds the maximum file size");
}
protected void ASPxSpreadsheet1_Saving(object source, DocumentSavingEventArgs e) {
ASPxSpreadsheet sh = source as ASPxSpreadsheet;
try {
// SqlDataSource1.Update(); // uncomment to update the data source
sh.JSProperties["cpSavingResult"] = "OK";
}
catch (Exception ex) {
sh.JSProperties["cpSavingResult"] = "ERROR";
}
e.Handled = true;
}
}
}