-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefault.aspx.cs
More file actions
48 lines (41 loc) · 1.68 KB
/
Default.aspx.cs
File metadata and controls
48 lines (41 loc) · 1.68 KB
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
using System;
using System.IO;
using System.Web.UI;
namespace WebEditor
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnUpload_Click(object sender, EventArgs e)
{
if (!fuFile.HasFile)
{
litStatus.Text = string.Empty;
return;
}
docEditor.SetDocumentFromBytes(fuFile.FileBytes, fuFile.FileName); // Carga el documento en el editor
litStatus.Text = string.Empty;
}
protected void btnDescargar_Click(object sender, EventArgs e)
{
// El evento puede acceder al documento editado solo si el ID del disparador se registró en el control OnlyOfficeEditor
byte[] documentBytes = docEditor.GetEditedDocumentBytes(); // Obtiene el documento editado como un arreglo de bytes
if (documentBytes == null || documentBytes.Length == 0)
{
litStatus.Text = "<span class='text-warning'>No hay documento editado para descargar.</span>";
return;
}
docEditor.ClearEditedDocument();
var ext = Path.GetExtension(docEditor.DocumentName ?? ".docx");
var fileName = docEditor.DocumentName ?? ("documento" + ext);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", documentBytes.Length.ToString());
Response.BinaryWrite(documentBytes);
Response.End();
}
}
}