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;
|
|
|
|
|
|
|
|
|
|
|
|
namespace webAgenciaVirtual
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Descripción breve de FileUploadHandler
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class FileUploadHandler : IHttpHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2018-07-12 19:43:14 +00:00
|
|
|
|
|
2018-06-28 17:44:24 +00:00
|
|
|
|
string pathrefer = context.Request.UrlReferrer.ToString();
|
2018-06-28 20:40:17 +00:00
|
|
|
|
//string Serverpath = HttpContext.Current.Server.MapPath("DocumentosSINORT");
|
|
|
|
|
|
string Serverpath = ConfigurationManager.AppSettings["FileRepository"].ToString();
|
2018-07-12 19:43:14 +00:00
|
|
|
|
if (context.Request.QueryString["id"] != null){
|
2018-06-29 20:40:24 +00:00
|
|
|
|
Serverpath += context.Request.QueryString["tipo"].ToString() + "\\" + context.Request.QueryString["id"].ToString() + "\\" + context.Request.QueryString["carpeta"].ToString();
|
2018-07-12 19:43:14 +00:00
|
|
|
|
}else
|
|
|
|
|
|
{
|
|
|
|
|
|
Serverpath += context.Request.QueryString["tipo"].ToString();
|
|
|
|
|
|
}
|
2018-06-28 17:44:24 +00:00
|
|
|
|
var postedFile = context.Request.Files[0];
|
|
|
|
|
|
string ext = Path.GetExtension(postedFile.FileName);
|
|
|
|
|
|
//if (ext == ".pdf" || ext == ".PDF")
|
|
|
|
|
|
//{
|
|
|
|
|
|
string file;
|
|
|
|
|
|
|
|
|
|
|
|
//For IE to get file name
|
|
|
|
|
|
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE")
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] files = postedFile.FileName.Split(new char[] { '\\' });
|
|
|
|
|
|
file = files[files.Length - 1].Replace(" ","_");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
file = postedFile.FileName.Replace(" ", "_");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-03 14:21:25 +00:00
|
|
|
|
file = postedFile.FileName.Replace(" ", "_");
|
2018-06-28 17:44:24 +00:00
|
|
|
|
if (!Directory.Exists(Serverpath))
|
|
|
|
|
|
Directory.CreateDirectory(Serverpath);
|
|
|
|
|
|
|
|
|
|
|
|
string fileDirectory = Serverpath;
|
|
|
|
|
|
if (context.Request.QueryString["fileName"] != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
file = context.Request.QueryString["fileName"].Replace(" ", "_");
|
|
|
|
|
|
if (File.Exists(fileDirectory + "\\" + file))
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(fileDirectory + "\\" + file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//string ext = Path.GetExtension(fileDirectory + "\\" + file);
|
|
|
|
|
|
//file = Guid.NewGuid() + ext;
|
|
|
|
|
|
|
|
|
|
|
|
fileDirectory = Serverpath + "\\" + file;
|
|
|
|
|
|
|
|
|
|
|
|
postedFile.SaveAs(fileDirectory);
|
|
|
|
|
|
|
|
|
|
|
|
context.Response.AddHeader("Vary", "Accept");
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (context.Request["HTTP_ACCEPT"].Contains("application/json"))
|
|
|
|
|
|
context.Response.ContentType = "application/json";
|
|
|
|
|
|
else
|
|
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//context.Response.Write("Success");
|
|
|
|
|
|
context.Response.ContentType = "text/plain";
|
|
|
|
|
|
context.Response.Write(file);
|
|
|
|
|
|
return;
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// context.Response.Write("errorEXT");
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
2018-07-12 19:43:14 +00:00
|
|
|
|
|
2018-06-28 17:44:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exp)
|
|
|
|
|
|
{
|
|
|
|
|
|
context.Response.Write(exp.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsReusable
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|