2018-06-28 17:44:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Web.Script.Serialization;
|
2018-07-19 16:37:48 +00:00
|
|
|
|
using System.Security.AccessControl;
|
2018-06-28 17:44:24 +00:00
|
|
|
|
|
2018-09-27 05:36:23 +00:00
|
|
|
|
|
2018-06-28 17:44:24 +00:00
|
|
|
|
namespace webAgenciaVirtual
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Descripción breve de FileUploadHandler
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FileUploadHandler : IHttpHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2018-09-27 05:36:23 +00:00
|
|
|
|
|
|
|
|
|
|
string Serverpath = ConfigurationManager.AppSettings["FileRepository"].ToString();
|
|
|
|
|
|
//Server.MapPath("../../DocsRespuesta/" + txtCedulaPropietario.Text.Trim() + "/" + ViewState["PKFORMULARIO"].ToString() + "/");
|
|
|
|
|
|
|
|
|
|
|
|
//String pathMail = ConfigurationManager.AppSettings["RutaPdf"].ToString() + txtCedulaPropietario.Text.Trim() + @"\" + ViewState["PKFORMULARIO"].ToString() + @"\";
|
|
|
|
|
|
|
2018-09-28 23:20:06 +00:00
|
|
|
|
//if (!Directory.Exists(Serverpath))
|
|
|
|
|
|
// Directory.CreateDirectory(Serverpath);
|
2018-09-27 05:36:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var postedFile = context.Request.Files[0];
|
|
|
|
|
|
string fecha = context.Request.QueryString["tipo"].ToString();
|
2018-09-28 23:20:06 +00:00
|
|
|
|
|
2018-09-27 05:36:23 +00:00
|
|
|
|
string ext = Path.GetExtension(postedFile.FileName);
|
|
|
|
|
|
string file;
|
|
|
|
|
|
file = postedFile.FileName.Replace(" ", "_");
|
2018-09-28 23:20:06 +00:00
|
|
|
|
string fileDirectory;
|
2018-09-27 05:36:23 +00:00
|
|
|
|
string[] Arraynombre = new string[2];
|
|
|
|
|
|
Arraynombre = file.Split('.');
|
|
|
|
|
|
var nom = Arraynombre[0];
|
|
|
|
|
|
file = nom + fecha + ext;
|
2018-09-28 23:20:06 +00:00
|
|
|
|
fileDirectory = nom + fecha;
|
|
|
|
|
|
|
2018-09-27 05:36:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Documento oDoc = new Documento();
|
|
|
|
|
|
//se transaforma el archivo a un arreglo de bytes
|
|
|
|
|
|
|
|
|
|
|
|
byte[] fileData = null;
|
|
|
|
|
|
using (var binaryReader = new BinaryReader(context.Request.Files[0].InputStream))
|
|
|
|
|
|
{
|
|
|
|
|
|
fileData = binaryReader.ReadBytes(context.Request.Files[0].ContentLength);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-28 23:20:06 +00:00
|
|
|
|
string strResultado = oDoc.Archivar_Documento(fileDirectory, file, fileData);
|
|
|
|
|
|
|
2018-09-27 05:36:23 +00:00
|
|
|
|
if (strResultado != string.Empty)
|
|
|
|
|
|
context.Response.Write("Error");
|
|
|
|
|
|
else
|
|
|
|
|
|
context.Response.Write("Success");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Response.AddHeader("Vary", "Accept");
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (context.Request["HTTP_ACCEPT"].Contains("application/json"))
|
|
|
|
|
|
context.Response.ContentType = "application/json";
|
|
|
|
|
|
else
|
2018-06-28 17:44:24 +00:00
|
|
|
|
context.Response.ContentType = "text/plain";
|
2018-09-27 05:36:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
|
|
|
|
//context.Response.Write(file);
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-28 17:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exp)
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Response.Write(exp.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsReusable
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|