public static FileMessage UploadFile(ref Telerik.Web.UI.UploadedFile file, String filePath) { Impersonate oImpersonate = new Impersonate(); Boolean wasImpersonated = Impersonate.isImpersonated(); try { if (!wasImpersonated && oImpersonate.ImpersonateValidUser() == FileMessage.ImpersonationFailed) { return(FileMessage.ImpersonationFailed); } else { file.SaveAs(filePath); return(FileMessage.FileCreated); } } catch { if (!wasImpersonated) { oImpersonate.UndoImpersonation(); } return(FileMessage.Catch); } finally { if (!wasImpersonated) { oImpersonate.UndoImpersonation(); } } }
public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments) { string physicalPath = this.GetPhysicalFromVirtualPath(path); if (physicalPath == null) { return(string.Empty); } physicalPath = PathHelper.AddEndingSlash(physicalPath, '\\') + name; file.SaveAs(physicalPath); // Returns the path to the newly created file return(PathHelper.AddEndingSlash(path, '/') + name); }
protected void RadUpload1_FileExists1(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e) { int counter = 1; Telerik.Web.UI.UploadedFile file = e.UploadedFile; string targetFolder = Server.MapPath("~/App_Uploads_Img/" + DropDownList1I.SelectedItem.Text + "/"); string targetFileName = Path.Combine(targetFolder, file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension()); while (System.IO.File.Exists(targetFileName)) { counter++; targetFileName = Path.Combine(targetFolder, file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension()); } file.SaveAs(targetFileName); GC.Collect(); }
protected void Page_Load(object sender, EventArgs e) { Callback = Request.QueryString["Callback"]; _4screen.CSB.Extensions.Business.TrackingManager.TrackEventPage(null, null, IsPostBack, LogSitePageType.WizardSpezial); if (!string.IsNullOrEmpty(Request.QueryString["CN"])) { folderId = Request.QueryString["CN"]; } else if (!string.IsNullOrEmpty(Request.QueryString["UI"])) { folderId = Request.QueryString["UI"]; } else if (!string.IsNullOrEmpty(Request.QueryString["ParentId"])) { folderId = Request.QueryString["ParentId"]; } if (RadUpload.UploadedFiles.Count > 0) { _4screen.CSB.ImageHandler.Business.ImageHandler imageHandler = new _4screen.CSB.ImageHandler.Business.ImageHandler(_4screen.CSB.Common.SiteConfig.MediaDomainName, ConfigurationManager.AppSettings["ConverterRootPath"], folderId, null, true, Server.MapPath("/Configurations")); Telerik.Web.UI.UploadedFile uploadedFile = RadUpload.UploadedFiles[0]; string originalExtension = uploadedFile.GetName().Substring(uploadedFile.GetName().LastIndexOf('.')); string archiveFolder = string.Format(@"{0}\{1}\BG\{2}", System.Configuration.ConfigurationManager.AppSettings["ConverterRootPathMedia"], folderId, PictureVersion.A); if (!Directory.Exists(archiveFolder)) { Directory.CreateDirectory(archiveFolder); } string archiveFilename = string.Format(@"{0}\{1}{2}", archiveFolder, imageHandler.ImageName, originalExtension); uploadedFile.SaveAs(archiveFilename); imageHandler.DoConvert(archiveFilename, actionProfileResizeLarge, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); imageHandler.DoConvert(archiveFilename, actionProfileResizeExtraSmall, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); } LoadPictures(); }
public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments) { string physicalPath = this.GetPhysicalFromVirtualPath(path); if (physicalPath == null) { return(string.Empty); } physicalPath = PathHelper.AddEndingSlash(physicalPath, '\\') + name; var ffile = new System.IO.FileInfo(physicalPath); if (ffile.Directory != null && !ffile.Directory.Exists) { ffile.Directory.Create(); } file.SaveAs(physicalPath); // Returns the path to the newly created file return(PathHelper.AddEndingSlash(path, '/') + name); }
protected void btnAgregarImagen_Click(object sender, ImageClickEventArgs e) { lblError.Text = ""; if (rdlOpcion.SelectedValue == "D") { if (lblReferencia.Text != "") { byte[] imagen = null; bool archivoValido = false; string extension = ""; if (AsyncUpload1.UploadedFiles.Count == 0) { lblError.Text = "Debe indicar el o los documentos a cargar"; } else { int idEmpresa = 0; int cliente = 0; Datos fotos = new Datos(); try { idEmpresa = Convert.ToInt32(Request.QueryString["e"].ToString()); } catch (Exception) { Response.Redirect("Default.aspx"); } try { cliente = Convert.ToInt32(lblIdCliente.Text); } catch (Exception) { cliente = 0; } //Documentos try { string ruta = Server.MapPath("~/TMP"); string filename = ""; // Si el directorio no existe, crearlo if (!Directory.Exists(ruta)) { Directory.CreateDirectory(ruta); } int documentos = AsyncUpload1.UploadedFiles.Count; int guardados = 0; for (int i = 0; i < documentos; i++) { filename = AsyncUpload1.UploadedFiles[i].FileName; string[] segmenatado = filename.Split(new char[] { '.' }); archivoValido = validaArchivo(segmenatado[1]); extension = segmenatado[1]; string archivo = String.Format("{0}\\{1}", ruta, filename); try { FileInfo file = new FileInfo(archivo); // Verificar que el archivo no exista if (File.Exists(archivo)) { file.Delete(); } if (extension.ToUpper() != "PDF") { System.Drawing.Image img = System.Drawing.Image.FromStream(AsyncUpload1.UploadedFiles[i].InputStream); img.Save(archivo); imagen = Imagen_A_Bytes(archivo); } else { Telerik.Web.UI.UploadedFile up = AsyncUpload1.UploadedFiles[i]; up.SaveAs(archivo); imagen = File.ReadAllBytes(archivo); } } catch (Exception) { imagen = null; } if (imagen != null) { string identificadorProceso = ddlEstatus.SelectedValue; bool agregado = datos.agregaDocumentosCliente(cliente, imagen, extension, lblReferencia.Text, idEmpresa, identificadorProceso); if (agregado) { guardados++; } } } lblError.Text = "Se guardaron " + guardados.ToString() + " imagenes de " + documentos.ToString() + " seleccionadas."; } catch (Exception) { imagen = null; } int empresa = 0; try { empresa = Convert.ToInt32(Request.QueryString["e"].ToString()); DataSet imagenes = fotos.obtieneDoctos(lblReferencia.Text, empresa, cliente); DataListFotosDanos.DataSource = imagenes; DataListFotosDanos.DataBind(); } catch (Exception) { DataListFotosDanos.DataSource = null; DataListFotosDanos.DataBind(); } } } else { lblError.Text = "Debe seleccionar un cliente"; } } else { lblError.Text = "La acción de agregar solo es accesible en la opción documentos"; } }
protected void Button1_Click(object sender, EventArgs e) { Telerik.Web.UI.UploadedFile file = this.RadUpload1.UploadedFiles[0]; file.SaveAs(Server.MapPath("/") + file.FileName); }
private void BindValidResults() { _4screen.CSB.ImageHandler.Business.ImageHandler imageHandler = new _4screen.CSB.ImageHandler.Business.ImageHandler(_4screen.CSB.Common.SiteConfig.MediaDomainName, ConfigurationManager.AppSettings["ConverterRootPath"], dataObject.UserID.ToString(), objectId.ToString(), true, Server.MapPath("/Configurations")); if (RadUpload1.UploadedFiles.Count > 0) { pnlUploadFinish.Visible = false; Telerik.Web.UI.UploadedFile uploadedFile = RadUpload1.UploadedFiles[0]; if (!string.IsNullOrEmpty(Request.QueryString["TemplateID"])) { Guid templateId = Request.QueryString["TemplateID"].ToGuid(); template = DataObject.Load <DataObject>(templateId, null, false); } if (template != null && template.State != ObjectState.Added) { Helper.SetActions(Helper.GetPictureFormatFromFilename(uploadedFile.GetName()), template.ObjectType, out actionProfileCropCheckAndArchive, out actionProfileResizeLarge, out actionProfileResizeMedium, out actionProfileResizeSmall, out actionProfileResizeExtraSmall, out actionProfileCrop, imageTypes); } else { Helper.SetActions(Helper.GetPictureFormatFromFilename(uploadedFile.GetName()), dataObject.ObjectType, out actionProfileCropCheckAndArchive, out actionProfileResizeLarge, out actionProfileResizeMedium, out actionProfileResizeSmall, out actionProfileResizeExtraSmall, out actionProfileCrop, imageTypes); } string originalExtension = uploadedFile.GetName().Substring(uploadedFile.GetName().LastIndexOf('.')); string archivedFilename = System.IO.Path.Combine(imageHandler.GetPhysicalImagePath(actionProfileCropCheckAndArchive), imageHandler.ImageName + originalExtension); uploadedFile.SaveAs(archivedFilename, true); imageHandler.DoConvert(archivedFilename, actionProfileCropCheckAndArchive, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); archivedFilename = imageHandler.TargetImage; int originalImageHeight = imageHandler.ImageInfo.Height; int originalImageWidth = imageHandler.ImageInfo.Width; int cropLimitHeight = imageHandler.OriginalCropHeight(actionProfileCropCheckAndArchive); int cropLimitWidth = imageHandler.OriginalCropWidth(actionProfileCropCheckAndArchive); int maxVisualWidthOrHeight = imageHandler.GetMaxVisualWidthOrHeight(actionProfileCropCheckAndArchive); if (originalImageHeight < cropLimitHeight && originalImageWidth < cropLimitWidth) // No need for cropping { imageHandler.DoConvert(archivedFilename, actionProfileResizeExtraSmall, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); imageHandler.DoConvert(archivedFilename, actionProfileResizeSmall, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); if (actionProfileResizeMedium != null) { imageHandler.DoConvert(archivedFilename, actionProfileResizeMedium, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); } imageHandler.DoConvert(archivedFilename, actionProfileResizeLarge, _4screen.CSB.ImageHandler.Business.ImageHandler.ReturnPath.Url); SaveDataObject(imageHandler.ImageName); if (string.IsNullOrEmpty(Request.QueryString["ReturnURL"])) { litScript.Text = "<script language=\"javascript\">$telerik.$(function() { RefreshParentPage(true); CloseWindow(); } );</script>"; } else { litScript.Text = string.Format("<script language=\"javascript\">$telerik.$(function() {{ RedirectParentPage('{0}'); CloseWindow(); }} );</script>", Encoding.ASCII.GetString(Convert.FromBase64String(Request.QueryString["ReturnURL"]))); } } else { ViewState["sourceImg"] = archivedFilename; ViewState["ImageWidth"] = originalImageWidth; ViewState["ImageHeight"] = originalImageHeight; ViewState["MaxSize"] = maxVisualWidthOrHeight; pnlCroping.Visible = true; pnlUploadFinish.Visible = false; pnlUpload.Visible = false; if (!string.IsNullOrEmpty(Request.QueryString["TemplateID"])) { this.PnlTitle.Visible = true; } if (originalImageHeight > originalImageWidth && originalImageHeight > maxVisualWidthOrHeight) { Crop.CroppedImageHeight = maxVisualWidthOrHeight; Crop.CroppedImageWidth = (int)((float)maxVisualWidthOrHeight * (float)originalImageWidth / (float)originalImageHeight); } else if (originalImageHeight < originalImageWidth && originalImageWidth > maxVisualWidthOrHeight) { Crop.CroppedImageHeight = (int)((float)maxVisualWidthOrHeight * (float)originalImageHeight / (float)originalImageWidth); Crop.CroppedImageWidth = maxVisualWidthOrHeight; } else if (originalImageWidth > maxVisualWidthOrHeight) { Crop.CroppedImageHeight = maxVisualWidthOrHeight; Crop.CroppedImageWidth = maxVisualWidthOrHeight; } else { Crop.CroppedImageHeight = originalImageHeight; Crop.CroppedImageWidth = originalImageWidth; } Crop.AllowQualityLoss = true; FileStream stream = File.Open(archivedFilename, FileMode.Open); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Dispose(); Crop.SourceImage = buffer; } } }