protected void BT_Upload_Fichier_Click(object sender, EventArgs e) { if (FU_Url.UploadedFiles.Count > 0) { UploadedFile file = FU_Url.UploadedFiles[0]; string guid = HF_id.Value; if (guid == "") { guid = Guid.NewGuid().ToString(); } string filename = Functions.ClearFileName("news_" + guid + file.GetExtension()); TXT_Url_Texte.Text = file.FileName.Substring(0, file.FileName.Length - file.GetExtension().Length); HL_Url.Text = filename; MemoryStream ms = new MemoryStream(); file.InputStream.CopyTo(ms, (int)file.InputStream.Length); Media media = new Media(); media.content = ms.GetBuffer(); media.content_size = media.content.Length; media.dt = DateTime.Now; media.w = 0; media.h = 0; media.name = filename; media.content_type = file.ContentType; Session[HL_Url.Text] = media; HL_Url.NavigateUrl = Const.MEDIA_DOWNLOAD_URL + "?id=" + filename; BT_Effacer_Fichier.Visible = true; if (file.ContentType.Equals("application/pdf")) { BT_Creer_Vignette.Visible = true; } } }
protected override void Save(UploadedFile file) { var size = file.ContentLength; var storeKey = file.ServerKey; var name = file.GetName(); var extension = file.GetExtension(); try { var directoryId = GetDirectoryId(); var result = ServiceContext.Invoke("addFile", (arg) => { arg["name"] = name; arg["storeKey"] = storeKey; arg["extension"] = extension; arg["size"] = size; arg["directoryId"] = directoryId; }); this.Response.Write(result.GetCode(false, false)); } catch (Exception ex) { Delete(storeKey); throw ex; } }
//private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file) //{ // const int total = 100; // RadProgressContext progress = RadProgressContext.Current; // for (int i = 0; i < total; i++) // { // progress["PrimaryTotal"] = total.ToString(); // progress["PrimaryValue"] = i.ToString(); // progress["PrimaryPercent"] = i.ToString(); // progress["CurrentOperationText"] = file.GetName() + " is being processed..."; // if (!Response.IsClientConnected) // { // //Cancel button was clicked or the browser was closed, so stop processing // break; // } // //Stall the current thread for 0.1 seconds // System.Threading.Thread.Sleep(100); // } //} public void ProcessVideo(UploadedFile VideoFile) { litCompleted.Text = ""; try { member = (Member)Session["Member"]; bool ValidExtention = true; string VideoTitle = string.Empty; string Ext = string.Empty; Video video = new Video(); video.Title = (txtTitle.Text != "") ? txtTitle.Text : "New video"; video.Description = (txtCaption.Text != "") ? txtCaption.Text : "No Description"; try { Ext = VideoFile.GetExtension(); } catch { Ext = "xxx"; ValidExtention = false; } Ext = Ext.Replace(".", ""); // upload the flv if (IsVideo(Ext)) { if (VideoFile.ContentLength > 150000) { Video.QueueVideoForEncoding(video, VideoFile.InputStream, Ext, member, VideoTitle); litCompleted.Text = "<script>parent.location.href='MyVideoGallery.aspx?p=1';</script><img src='images/check.gif'/> Your video was successfully uploaded "; } else { litCompleted.Text = "<img src='images/na.gif'/> Your video must be at least 2 seconds long"; } } else { if (ValidExtention) { litCompleted.Text = "<img src='images/na.gif'/> Videos with the extention <strong>" + Ext + "</strong> arent supported"; } else { litCompleted.Text = "<img src='images/na.gif'/> Videos files must have an extention name. For example: .avi or .mov"; } } } catch (Exception ex) { string MachineName = Environment.MachineName; Next2Friends.Data.Trace.Tracer(ex.ToString(), "RadVideoUpload"); } }
protected void FileUploadFlightInfo_FileUploaded(object sender, FileUploadedEventArgs e) { UploadedFile file = e.File; fileExtension = file.GetExtension(); fileName = file.GetName(); path = Server.MapPath("~/Upload/"); file.SaveAs(path + fileName); }
private string SaveFileIntoServer(UploadedFile file, string strGuid, string strPath) { fileExtension = file.GetExtension(); string strRenameFilename = file.GetName(); strRenameFilename = strRenameFilename.Replace(' ', '_'); //string newFileName = advisorVo.advisorId + "_" + strGuid + "_" + strRenameFilename; string newFileName = strRenameFilename; // Save adviser repository file in the path file.SaveAs(strPath + "\\" + newFileName); return(newFileName); }
protected void UploadButton_Click(object sender, EventArgs e) { if (RadUploadControl.InvalidFiles.Count > 0) { StringBuilder response = new StringBuilder("<br/>There was an error while registering your template<br/>"); UploadedFile file = RadUploadControl.InvalidFiles[0]; if (file.ContentLength >= RadUploadControl.MaxFileSize) { response.Append("Maximum file size: " + RadUploadControl.MaxFileSize.ToString() + " bytes"); } else if (!RadUploadControl.AllowedFileExtensions.Contains(file.GetExtension())) { response.Append("Allowed file extensions: " + string.Join(",", RadUploadControl.AllowedFileExtensions)); } else { response.Append("Your template could not be uploaded"); } response.Append("<br/><br/>"); ErrorLabel.Text = response.ToString(); ErrorLabel.ForeColor = Color.Red; } else if (RadUploadControl.UploadedFiles.Count == 1) { string physicalPath = AppDomain.CurrentDomain.BaseDirectory; var templateteImporter = new TemplateImporter( RadUploadControl.UploadedFiles[0].GetName(), physicalPath ); bool success = templateteImporter.Import(); if (success) { ErrorLabel.Text = "Upload successful"; } else { ErrorLabel.Text = "An error occured while registering the template"; } ErrorLabel.ForeColor = Color.LightGreen; } }
protected void DosyalariSistemeUygunBicimdeYukle() { try { //new Aspose.Pdf.License().SetLicense(LicenseHelper.License.LStream); UploadedFile file = ctlFileUpl.UploadedFiles[0]; EFDal e = new EFDal(); Guid DosyaAdi = Guid.NewGuid(); var usr = UserManager.GetCurrentUser(); string usrName = usr.Identity.Name; int BolgeKodu = e.kal_BolgeKoduDon(usrName); string dosyaYolu = Server.MapPath("~/DosyaSistemi/"); dosyaYolu += BolgeKodu.ToString(); dosyaYolu += '\\' + DateTime.Now.Year.ToString() + '\\' + DosyaAdi.ToString() + file.GetExtension(); string DosyaAdiveUzantisiOlmadandosyaYolu = Server.MapPath("~/DosyaSistemi/") + BolgeKodu.ToString() + '\\' + DateTime.Now.Year.ToString() + '\\'; //string targetFolder = dosyaYolu; //string targetFileName = Path.Combine(targetFolder, DosyaAdi + file.GetExtension()); string targetFileName = dosyaYolu; file.SaveAs(targetFileName); //Şimdi veritabanına kaydı işle.. EFDal ed = new EFDal(); bool basarim = ed.IstekDokumanlariAdd(IstId, dosyaYolu, ImzaliDokumanTipleriId, ed.UserNamedenPersonelUNDon(Context.User.Identity.Name), DateTime.Now, false, txtAciklama.Text.Trim()); ////Dosya yüklendiği orijinal hali ile sitemde su anda, bu dosyayı pdf e çevirmemiz gerekli şimdi //switch (file.GetExtension()) //{ // case ".doc": // PDFCevirici.WordToPDF(targetFileName, DosyaAdiveUzantisiOlmadandosyaYolu + DosyaAdi + ".pdf"); // break; // case ".docx": // PDFCevirici.DOCXToPDF(targetFileName, DosyaAdiveUzantisiOlmadandosyaYolu + DosyaAdi + ".pdf"); // break; // case ".xls": // PDFCevirici.ExcelToPDF(targetFileName, DosyaAdiveUzantisiOlmadandosyaYolu + DosyaAdi + ".pdf"); // break; // case ".xlsx": // PDFCevirici.ExcelToPDF(targetFileName, DosyaAdiveUzantisiOlmadandosyaYolu + DosyaAdi + ".pdf"); // break; // case ".pdf": // //Hiçbirşey yapma // break; //} ////string kapakPDFDosyasi = e.IstIddenKapakPDFninPathiniDon(Convert.ToInt32(Request["IstId"])); //string veriSayfalariIcinSonucDosyaAdresi = DosyaAdiveUzantisiOlmadandosyaYolu + DosyaAdi + ".pdf"; ////Aspose.Pdf.Document pdfKapak = new Aspose.Pdf.Document(kapakPDFDosyasi); //Aspose.Pdf.Document pdfVeri = new Aspose.Pdf.Document(veriSayfalariIcinSonucDosyaAdresi); ////pdfKapak.Pages.Add(pdfVeri.Pages); ////pdfKapak.Save(kapakPDFDosyasi); //lblUplUyari.ForeColor = System.Drawing.Color.LimeGreen; ////Şimdi gönderilen sertifika verisi dosyasını veritabanına işlemek için path ve dosyaadi bilgisini oluştur. ////string bak = dosyaYolu; ////2 nolu dokuman Sertifika verisine karsilik geliyor ////Burada gridi yeniden bağlamak gerekiyor //File.Delete(DosyaAdiveUzantisiOlmadandosyaYolu + DosyaAdi + file.GetExtension()); //File.Delete(veriSayfalariIcinSonucDosyaAdresi);//veri sayfalarından oluşan pdf i de sil //e.spImzaliDosyalaraEkle(Convert.ToInt32(Request["IstId"]), DosyaAdi + ".pdf", 2, Guid.Empty, // e.UserNamedenUserIdDon(usrName), dosyaYolu, ".pdf"); ////Şİmdi bu dosya kal. yapan ve müdür tarafından e-imza bekliyor. Bu yızden bunu imzabekleyenler tablosuna ekle //int imzaliDosyaId = e.IstIddenSertifikaKapagininImzaliDosyalarIdsiniDon(Convert.ToInt32(Request["IstId"])); //e.spImzaBekleyenDokumanlaraEkle(imzaliDosyaId, e.UserNamedenPersonelUNDon(Context.User.Identity.Name), false, true, Convert.ToInt32(Request["IstId"])); lblUplUyari.ForeColor = System.Drawing.Color.Green; lblUplUyari.Text = "Dosya başarıyla yüklenmiştir..."; } catch (Exception exc) { // UploadedFile file = upl.UploadedFiles[0]; lblUplUyari.ForeColor = System.Drawing.Color.Red; lblUplUyari.Text = "Dosya yüklenemedi! Dosya boyutu 10 MB'dan büyük olamaz. Lütfen kontrol ediniz.<br>Hata:" + exc.Message; } }
private void ExtrairArquivoZip(UploadedFile arquivo, string pastaDeDestino) { IList<IRevistaDePatente> listaRevistasAProcessar = new List<IRevistaDePatente>(); var revistaDePatente = FabricaGenerica.GetInstancia().CrieObjeto<IRevistaDePatente>(); var numeroRevista = arquivo.GetNameWithoutExtension(); revistaDePatente.NumeroRevistaPatente = Convert.ToInt32(numeroRevista.Substring(0, 1).ToUpper().Equals("P") ? numeroRevista.Substring(1, 4) : numeroRevista); var pastaDeDestinoTemp = Server.MapPath(UtilMP.URL_REVISTA_PATENTE + "/temp/"); Directory.CreateDirectory(pastaDeDestinoTemp); var caminhoArquivoZip = Path.Combine(pastaDeDestinoTemp, revistaDePatente.NumeroRevistaPatente + arquivo.GetExtension()); arquivo.SaveAs(caminhoArquivoZip, true); Util.DescompacteArquivoZip(caminhoArquivoZip, pastaDeDestinoTemp); File.Delete(caminhoArquivoZip); var dirInfo = new DirectoryInfo(pastaDeDestinoTemp); FileInfo[] arquivos = dirInfo.GetFiles(); foreach (var arquivoDaPasta in arquivos) { var caminhoArquivoAntigo = Path.Combine(pastaDeDestinoTemp, arquivoDaPasta.Name); if (arquivoDaPasta.Name.Equals("P" + revistaDePatente.NumeroRevistaPatente + arquivoDaPasta.Extension)) { var arquivoNovo = arquivoDaPasta.Name.Replace("P" + revistaDePatente.NumeroRevistaPatente + arquivoDaPasta.Extension, revistaDePatente.NumeroRevistaPatente.ToString() + arquivoDaPasta.Extension); var caminhoArquivoNovo = Path.Combine(pastaDeDestino, arquivoNovo); File.Delete(caminhoArquivoNovo); File.Move(caminhoArquivoAntigo, caminhoArquivoNovo); File.Delete(caminhoArquivoAntigo); revistaDePatente.ExtensaoArquivo = arquivoDaPasta.Extension; listaRevistasAProcessar.Add(revistaDePatente); MostraListaRevistasAProcessar(listaRevistasAProcessar); return; } if (arquivoDaPasta.Name.Replace(arquivoDaPasta.Extension, "").Equals(revistaDePatente.NumeroRevistaPatente.ToString())) { var arquivoNovo = revistaDePatente.NumeroRevistaPatente.ToString() + arquivoDaPasta.Extension; var caminhoArquivoNovo = Path.Combine(pastaDeDestino, arquivoNovo); File.Delete(caminhoArquivoNovo); File.Move(caminhoArquivoAntigo, caminhoArquivoNovo); File.Delete(caminhoArquivoAntigo); revistaDePatente.ExtensaoArquivo = arquivoDaPasta.Extension; listaRevistasAProcessar.Add(revistaDePatente); MostraListaRevistasAProcessar(listaRevistasAProcessar); return; } } revistaDePatente.ExtensaoArquivo = arquivo.GetExtension(); listaRevistasAProcessar.Add(revistaDePatente); MostraListaRevistasAProcessar(listaRevistasAProcessar); }
//private void LooongMethodWhichUpdatesTheProgressContext(UploadedFile file) //{ // const int total = 100; // RadProgressContext progress = RadProgressContext.Current; // for (int i = 0; i < total; i++) // { // progress["PrimaryTotal"] = total.ToString(); // progress["PrimaryValue"] = i.ToString(); // progress["PrimaryPercent"] = i.ToString(); // progress["CurrentOperationText"] = file.GetName() + " is being processed..."; // if (!Response.IsClientConnected) // { // //Cancel button was clicked or the browser was closed, so stop processing // break; // } // //Stall the current thread for 0.1 seconds // System.Threading.Thread.Sleep(100); // } //} public void ProcessVideo(UploadedFile VideoFile) { litCompleted.Text = ""; try { member = (Member)Session["Member"]; bool ValidExtention = true; string VideoTitle = string.Empty; string Ext = string.Empty; Video video = new Video(); video.Title = (txtTitle.Text != "") ? txtTitle.Text : "New video"; video.Description = (txtCaption.Text != "") ? txtCaption.Text : "No Description"; try { Ext = VideoFile.GetExtension(); } catch { Ext = "xxx"; ValidExtention = false; } Ext = Ext.Replace(".", ""); // upload the flv if (IsVideo(Ext)) { if (VideoFile.ContentLength > 150000) { Video.QueueVideoForEncoding(video, VideoFile.InputStream, Ext, member, VideoTitle); litCompleted.Text = "<script>parent.location.href='MyVideoGallery.aspx?p=1';</script><img src='images/check.gif'/> Your video was successfully uploaded "; } else { litCompleted.Text = "<img src='images/na.gif'/> Your video must be at least 2 seconds long"; } } else { if (ValidExtention) litCompleted.Text = "<img src='images/na.gif'/> Videos with the extention <strong>" + Ext + "</strong> arent supported"; else litCompleted.Text = "<img src='images/na.gif'/> Videos files must have an extention name. For example: .avi or .mov"; } } catch(Exception ex) { string MachineName = Environment.MachineName; Next2Friends.Data.Trace.Tracer(ex.ToString(), "RadVideoUpload"); } }
protected void UpdatePhoto(object sender, EventArgs e) { if (ruUserImage.UploadedFiles.Count > 0) { newFile = ruUserImage.UploadedFiles[0]; /* is the file name of the uploaded file 50 characters or less? * The database field that holds the file name is 50 chars. * */ if (newFile.ContentLength > AppSettings.ProfileImageMaxFileSize) { lblUpdateResults.Text = "The file being imported is too big. Please select another file."; } else { if (newFile.GetName().Length <= AppSettings.ProfileImageMaxFileNameLength) { var uploadFolder = Server.MapPath(AppSettings.ProfileImageUserWebPath); string newFileName; do { newFileName = (Path.GetRandomFileName()).Replace(".", "") + newFile.GetExtension(); } while (System.IO.File.Exists(Path.Combine(uploadFolder, newFileName))); try { newFile.SaveAs(Path.Combine(uploadFolder, newFileName)); var oUser = SessionObject.LoggedInUser; var successful = oUser.UpdateUserImageFilename(newFileName); if (successful) { //attempt to delete the old file if (imgPhoto.Src != "/Images/person.png") { var oldFilePath = Server.MapPath(imgPhoto.Src); File.Delete(oldFilePath); } oUser.ImageFilename = newFileName; SessionObject.LoggedInUser = oUser; imgPhoto.Src = AppSettings.ProfileImageUserWebPath + "/" + newFileName; } else { lblUpdateResults.Text = "Database error. Please contact system administrator."; } } catch (Exception ex) { lblUpdateResults.Text = "Image Import unsuccessful. Please contact system adminstrator."; } } else { lblUpdateResults.Text = "Image filename length must be 50 characters or less. Please rename the file and try again."; } } } else { lblUpdateResults.Text = "Image import unsuccessful. No image specified."; } }
public string InsertImage(UploadedFile file, string userID) { string pCodArchivo = string.Empty; DBConn oConn = new DBConn(); try { byte[] imageData = GetImageBytes(file.InputStream); StringBuilder sPath = new StringBuilder(); StringBuilder sFile = new StringBuilder(); sPath.Append(HttpContext.Current.Server.MapPath(".")); sPath.Append(@"\rps_onlineservice\"); sPath.Append(@"\contenido\"); sPath.Append(@"\contenido_"); sPath.Append(userID); if (!Directory.Exists(sPath.ToString())) { Directory.CreateDirectory(sPath.ToString()); } if (oConn.Open()) { oConn.BeginTransaction(); ObjectModel oObjectModel = new ObjectModel(ref oConn); pCodArchivo = oObjectModel.getCodeKey("CMS_ARCHIVOS"); sPath.Append(@"\").Append(pCodArchivo).Append(file.GetExtension()); sFile.Append(pCodArchivo).Append(file.GetExtension()); File.WriteAllBytes(sPath.ToString(), imageData); CmsArchivos oArchivos = new CmsArchivos(ref oConn); oArchivos.CodArchivo = pCodArchivo; oArchivos.Accion = "CREAR"; oArchivos.CodContenido = userID; oArchivos.DateArchivo = DateTime.Now.ToString(); oArchivos.NomArchivo = sFile.ToString(); oArchivos.ExtArchivo = file.GetExtension(); oArchivos.Put(); if (string.IsNullOrEmpty(oArchivos.Error)) { oConn.Commit(); string cPath = HttpContext.Current.Server.MapPath(".") + @"\binary\"; string sFileUsrArchivo = "ContenidoArchivo_" + userID + ".bin"; oArchivos.SerializaTblArchivo(ref oConn, cPath, sFileUsrArchivo); } else { oConn.Rollback(); } oConn.Close(); } } catch (Exception Ex) { if (oConn.bIsOpen) { oConn.Rollback(); oConn.Close(); } } return(pCodArchivo); }
public string InsertImage(UploadedFile file, string userID) { string pCodArchivo = string.Empty; DBConn oConn = new DBConn(); try { byte[] imageData = GetImageBytes(file.InputStream); StringBuilder sPath = new StringBuilder(); StringBuilder sFile = new StringBuilder(); sPath.Append(HttpContext.Current.Server.MapPath(".")); sPath.Append(@"\rps_onlineservice\"); sPath.Append(@"\escorts\"); sPath.Append(@"\escort_"); sPath.Append(userID); if (!Directory.Exists(sPath.ToString())) { Directory.CreateDirectory(sPath.ToString()); } if (oConn.Open()) { oConn.BeginTransaction(); //ObjectModel oObjectModel = new ObjectModel(ref oConn); //pCodArchivo = oObjectModel.getCodeKey("SYS_ARCHIVOS_USUARIOS"); StringBuilder sNameFile = new StringBuilder(); sNameFile.Append(DateTime.Now.Year.ToString()); sNameFile.Append(DateTime.Now.Month.ToString()); sNameFile.Append(DateTime.Now.Day.ToString()); sNameFile.Append(DateTime.Now.Hour.ToString()); sNameFile.Append(DateTime.Now.Minute.ToString()); sNameFile.Append(DateTime.Now.Millisecond.ToString()); sPath.Append(@"\").Append(sNameFile.ToString()).Append(file.GetExtension()); sFile.Append(sNameFile.ToString()).Append(file.GetExtension()); File.WriteAllBytes(sPath.ToString(), imageData); imageData = null; setWaterMark(sPath); SysArchivosUsuarios oArchivosUsuarios = new SysArchivosUsuarios(ref oConn); //oArchivosUsuarios.CodArchivo = pCodArchivo; oArchivosUsuarios.Accion = "CREAR"; oArchivosUsuarios.CodUsuario = userID; oArchivosUsuarios.DateArchivo = DateTime.Now.ToString(); oArchivosUsuarios.NomArchivo = sFile.ToString(); oArchivosUsuarios.Put(); pCodArchivo = oArchivosUsuarios.CodArchivo; if (string.IsNullOrEmpty(oArchivosUsuarios.Error)) { oConn.Commit(); string cPath = HttpContext.Current.Server.MapPath(".") + @"\binary\"; string sFileUsrArchivo = "UserArchivo_" + userID + ".bin"; oArchivosUsuarios.SerializaTblUserArchivo(ref oConn, cPath, sFileUsrArchivo); } else { oConn.Rollback(); } oConn.Close(); } } catch (Exception Ex) { if (oConn.bIsOpen) { oConn.Rollback(); oConn.Close(); } } return(pCodArchivo); }
protected void RadUpload4_FileExists(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e) { int counter = 1; UploadedFile file = e.UploadedFile; string targetFolder = getpath(Request["pg"].ToString()) + RadTreeView1.SelectedNode.FullPath.Substring(getmainfolder(Request["pg"].ToString()).Length + 1).Replace("/", "\\"); 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); }