示例#1
0
 protected void afDosnload_OnUploadedComplete(object sender, AsyncFileUploadEventArgs e)
 {
     try
     {
         AsyncFileUpload uploadControl = (AsyncFileUpload)sender;
         //ParametrosGenerales generales = _servicioParametros.ObtenerParametrosGenerales();
         //Int64 sumaArchivos = Int64.Parse(Session["FileSize"].ToString());
         //sumaArchivos += int.Parse(e.FileSize);
         //if (!Directory.Exists(BusinessVariables.Directorios.RepositorioTemporalInformacionConsulta))
         //    Directory.CreateDirectory(BusinessVariables.Directorios.RepositorioTemporalInformacionConsulta);
         //if ((sumaArchivos / 1024) > int.Parse(generales.TamanoDeArchivo))
         //    throw new Exception(string.Format("El tamaño maximo de carga es de {0}MB", generales.TamanoDeArchivo));
         uploadControl.SaveAs(BusinessVariables.Directorios.RepositorioTemporal + e.FileName.Split('\\').Last());
         Session["ImagenArea"] = e.FileName.Split('\\').Last();
         //hfFileName.Value = e.FileName.Split('\\').Last();
     }
     catch (Exception ex)
     {
         if (_lstError == null)
         {
             _lstError = new List <string>();
         }
         _lstError.Add(ex.Message);
         Alerta = _lstError;
     }
 }
示例#2
0
        public contentUpload uploaderFile(AsyncFileUpload fileUpload)
        {
            List <string> errorMessage = new List <string>();
            List <string> fileExt      = new List <string>();

            contentUpload cu = new contentUpload();

            fileExt.Add(".jpg");
            fileExt.Add(".png");

            if (fileUpload.PostedFile.ContentLength >= 100000)
            {
                errorMessage.Add("file terlalu besar, maximal 100 kb");
            }

            if (!fileExt.Contains(System.IO.Path.GetExtension(fileUpload.FileName)))
            {
                errorMessage.Add("hanya file jpg atau png yang diperbolehkan");
            }

            if (errorMessage.Count == 0)
            {
                fileUpload.SaveAs(Server.MapPath("Files/") +
                                  Guid.NewGuid().ToString() +
                                  System.IO.Path.GetExtension(fileUpload.FileName));

                cu.fileName = Server.MapPath("Files/") +
                              Guid.NewGuid().ToString() +
                              System.IO.Path.GetExtension(fileUpload.FileName);
            }

            return(cu);
        }
示例#3
0
 void asyncFileUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
 {
     try
     {
         List <string> lstArchivo = Session["Files"] == null ? new List <string>() : (List <string>)Session["Files"];
         if (lstArchivo.Any(archivosCargados => archivosCargados.Split('_')[0] == e.FileName.Split('\\').Last()))
         {
             return;
         }
         string extension = Path.GetExtension(e.FileName.Split('\\').Last());
         if (extension == null)
         {
             return;
         }
         string          filename      = string.Format("{0}_{1}_{2}{3}{4}{5}{6}{7}{8}", e.FileName.Split('\\').Last().Replace(extension, string.Empty), "ticketid", DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, extension);
         AsyncFileUpload uploadControl = (AsyncFileUpload)sender;
         if (!Directory.Exists(BusinessVariables.Directorios.RepositorioTemporalMascara))
         {
             Directory.CreateDirectory(BusinessVariables.Directorios.RepositorioTemporalMascara);
         }
         uploadControl.SaveAs(BusinessVariables.Directorios.RepositorioTemporalMascara + filename);
         //Session[uploadControl.ID] = filename;
         lstArchivo.Add(filename);
         //Session["Files"] = lstArchivo;
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        //public ExtenssionMethods()
        //{
        //    //
        //    // TODO: Add constructor logic here
        //    //
        //}
        public static bool UploadFile(this AsyncFileUpload FileUpload, string extendname, string path, out string FileName)
        {
            string file = extendname + FileUpload.FileName;

            FileUpload.SaveAs(HttpContext.Current.Server.MapPath(path + file));
            FileName = file;
            return(true);
        }
示例#5
0
        protected void afuUploader_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            AsyncFileUpload afuUploader = sender as AsyncFileUpload;
            string          fileName    = afuUploader.FileName;

            if (afuUploader != null)
            {
                string uploadedFilePath = PathHelper.GetFileSystemPath(Constants.Paths.MultimediaStorageRoot, _tmpUploadPath, fileName);
                afuUploader.SaveAs(uploadedFilePath);
            }
        }
示例#6
0
        void AsyncFileUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
        {
            try
            {
                string      path           = "";
                string      urlFile        = "";
                SqlFunction sqlFun         = new SqlFunction(HttpContext.Current.Session.GetConnectionString2());
                string      duongdanfilecu = sqlFun.GetOneStringField(@"select top 1 duongDanFile from  dbo.tblNghiemThu WHERE sttNghiemThupr='" + hdfSttNT.Value.ToString() + "'");
                //lấy mã dự án
                string sttDuAnpr = sqlFun.GetOneStringField("select top 1 CONVERT(NVARCHAR(50),sttDuAnpr_sd) from tblNghiemThu where sttNghiemThupr='" + hdfSttNT.Value.ToString() + "'");
                string tenFile   = e.filename;//"VanBan" + hdfSTTVanBan.Value + ".pdf";
                if (!System.IO.Directory.Exists(Server.MapPath("~/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + sttDuAnpr + "/nghiemThu")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + sttDuAnpr + "/nghiemThu"));
                }
                string strDate       = DateTime.Now.ToString("dd_MM_yy_hhmmss");
                string fileExtension = Path.GetExtension(tenFile).Replace("-", "");
                tenFile = tenFile.Substring(tenFile.LastIndexOf("\\\\") + 1);
                tenFile = tenFile.Substring(0, tenFile.LastIndexOf(fileExtension)) + strDate + fileExtension;
                tenFile = tenFile.Replace(" ", "");
                //path = string.Concat(Server.MapPath("/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/KHoachDThau/"));
                path = string.Concat(Server.MapPath("/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + sttDuAnpr + "/nghiemThu/" + tenFile + ""));

                if (!System.IO.File.Exists(path))
                {
                    //save lại file mới
                    AsyncFileUpload.SaveAs(path);
                    urlFile = "/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + sttDuAnpr + "/nghiemThu/" + tenFile + "";
                    sqlFun.ExeCuteNonQuery("UPDATE dbo.tblNghiemThu SET duongDanFile=N'" + urlFile + "' WHERE sttNghiemThupr='" + hdfSttNT.Value.ToString() + "'");
                    //lấy mã dự án
                    //xóa file cũ
                    string duongdanfilecu_ = HttpContext.Current.Server.MapPath(duongdanfilecu.ToString());
                    if (System.IO.File.Exists(duongdanfilecu_))
                    {
                        System.IO.File.Delete(duongdanfilecu_);
                    }
                    AsyncFileUpload.ClearState();
                    AsyncFileUpload.Dispose();
                    return;
                }
                else
                {
                    //Xoa file neu da ton tai
                    System.IO.File.Delete(path);
                    AsyncFileUpload_UploadedComplete(sender, e);
                }
            }
            catch
            {
                return;
            }
            AsyncFileUpload.Dispose();
        }
示例#7
0
        public static string SaveImageAsync(AsyncFileUpload Fu, string prefix, string localImagePath)
        {
            if (!Directory.Exists(localImagePath))
            {
                Directory.CreateDirectory(localImagePath);
            }
            string strImage = string.Empty;
            string SavePath = string.Empty;

            //SavePath = GetImagePathWithFileName(3, prefix, localImagePath);
            SavePath  = localImagePath;
            SavePath += '\\' + prefix;
            Fu.SaveAs(SavePath);
            Fu.FileContent.Dispose();
            strImage = SavePath;
            //Fu.PostedFile.ContentLength
            return(strImage);
        }
示例#8
0
        protected void afuArchivo_OnUploadedComplete(object sender, AsyncFileUploadEventArgs e)
        {
            try
            {
                if (TamañoArchivo > 0)
                {
                    if ((double.Parse(e.FileSize) / 1024) > (10 * 1024))
                    {
                        Response.Write("Size is limited to 2MB");
                        throw new Exception(string.Format("El tamaño maximo de carga es de {0}MB", "10"));
                    }
                }


                List <string> lstArchivo = Session["FilesComment"] == null ? new List <string>() : (List <string>)Session["FilesComment"];
                if (lstArchivo.Any(archivosCargados => archivosCargados.Split('_')[0] == e.FileName.Split('\\').Last()))
                {
                    return;
                }
                string extension = Path.GetExtension(e.FileName.Split('\\').Last());
                if (extension == null)
                {
                    return;
                }
                string          filename      = string.Format("{0}_{1}_{2}{3}{4}{5}{6}{7}{8}", e.FileName.Split('\\').Last().Replace(extension, string.Empty), lblNoticket.Text, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, extension);
                AsyncFileUpload uploadControl = (AsyncFileUpload)sender;
                if (!Directory.Exists(BusinessVariables.Directorios.RepositorioTemporalMascara))
                {
                    Directory.CreateDirectory(BusinessVariables.Directorios.RepositorioTemporalMascara);
                }
                uploadControl.SaveAs(BusinessVariables.Directorios.RepositorioTemporalMascara + filename);
                lstArchivo.Add(filename);
                Session["FilesComment"] = lstArchivo;
            }
            catch (Exception ex)
            {
                if (_lstError == null)
                {
                    _lstError = new List <string>();
                }
                _lstError.Add(ex.Message);
                Alerta = _lstError;
            }
        }
 public void MWIntakeUpload(AsyncFileUpload fileUpload, MWIntakeCommon.FileCategory fileCat, string region, string market)
 {
     if (!Directory.Exists(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region))
     {
         Directory.CreateDirectory(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region);
     }
     if (!Directory.Exists(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market))
     {
         Directory.CreateDirectory(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market);
     }
     if (!Directory.Exists(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market + "\\" + siteid))
     {
         Directory.CreateDirectory(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market + "\\" + siteid);
     }
     if (!Directory.Exists(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market + "\\" + siteid + "\\Requestor_" + requester))
     {
         Directory.CreateDirectory(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market + "\\" + siteid + "\\Requestor_" + requester);
     }
     fileUpload.SaveAs(MWIntakeCommon.Utility.MWIntakeUploads + "\\" + region + "\\" + market + "\\" + siteid + "\\Requestor_" + requester + "\\" + Path.GetFileNameWithoutExtension(fileUpload.FileName) + fileCat + Path.GetExtension(fileUpload.FileName));
 }
示例#10
0
 protected void afDosnload_OnUploadedComplete(object sender, AsyncFileUploadEventArgs e)
 {
     try
     {
         AsyncFileUpload uploadControl = (AsyncFileUpload)sender;
         if (File.Exists(BusinessVariables.Directorios.RepositorioCarrusel + e.FileName.Split('\\').Last()))
         {
             File.Delete(BusinessVariables.Directorios.RepositorioCarrusel + e.FileName.Split('\\').Last());
         }
         uploadControl.SaveAs(BusinessVariables.Directorios.RepositorioCarrusel + e.FileName.Split('\\').Last());
     }
     catch (Exception ex)
     {
         if (_lstError == null)
         {
             _lstError = new List <string>();
         }
         _lstError.Add(ex.Message);
         Alerta = _lstError;
     }
 }
示例#11
0
        public static Guid UploadAttach(AsyncFileUpload fu)
        {
            if (!fu.HasFile || fu.FileName.Length == 0)
            {
                throw new BusinessObjectLogicException("Please select upload file!");
            }

            string path = null;

            try
            {
                string subDirectory = DateTime.Now.ToString("yyyyMM") + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd");
                string directory    = System.Configuration.ConfigurationManager.AppSettings["File"] + subDirectory;

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string title = Path.GetFileName(fu.FileName);
                string ext   = Path.GetExtension(fu.FileName);

                path = Path.DirectorySeparatorChar + Path.GetRandomFileName() + ext;

                fu.SaveAs(directory + path);


                Attachment attach = new Attachment(UserHelper.UserName);
                attach.Title = title;
                attach.Path  = subDirectory + path;

                new AttachmentBl().AddAttach(attach);

                return(attach.UID);
            }
            catch
            {
                throw new BusinessObjectLogicException("File upload fail!");
            }
        }