private static void UploadInsuranceDocument(int ID, UploadedFileCollection files) { String directory = HttpContext.Current.Server.MapPath("~/uploads"); directory = directory + "\\" + ID.ToString(); // build the path to the file upload // if the directory doesn't exist already, create it if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } // upload the file and rename it to attachment.pdf foreach (UploadedFile file in files) { String filename = "attachment" + file.GetExtension(); file.SaveAs(directory + "\\" + filename, true); } }
private void UploadAttachmentFiles(string folderName, UploadedFileCollection uploadFiles) { foreach (UploadedFile uploadFile in uploadFiles) { try { string leaveFolderPath = Server.MapPath("~/dll/"); string fullFolderPath = leaveFolderPath + folderName; if (!Directory.Exists(fullFolderPath)) { Directory.CreateDirectory(fullFolderPath); } string fullFilePath = fullFolderPath + "\\" + uploadFile.FileName; uploadFile.SaveAs(fullFilePath, true); } catch { throw new IOException(uploadFile.FileName + " attachment upload fail"); } } }
//protected void BT1_Click(object sender, EventArgs e) //{ // Panel0.Visible = true; // Panel1.Visible = false; // Panel2.Visible = true; // Panel3.Visible = false; //} protected void BT2_Click(object sender, EventArgs e) { try { UploadedFileCollection liste = RadUpload1.UploadedFiles; String folder = _folder; if (RadUpload1.UploadedFiles.Count > 0 && !string.IsNullOrEmpty(_folder)) { //List<Media> lesMedias = new List<Media>(); //if (Session["lesmediasTEMP"] != null) //{ // lesMedias = (List<Media>)Session["lesmediasTEMP"]; //} foreach (UploadedFile file in RadUpload1.UploadedFiles) { //Files.Add(file.FileName); //string guid = Guid.NewGuid().ToString(); //string filename = Functions.ClearFileName(guid + ".jpg"); Bitmap bmp = new Bitmap(file.InputStream); //bmp = Functions.ThumbByWidth(bmp, AIS.PAULHE.Const.CONTENU_PHOTOS_WIDTH); MemoryStream ms = new MemoryStream(); //bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //Media media = new Media(); //media.content = ms.GetBuffer(); //media.content_size = media.content.Length; //media.dt = DateTime.Now; //media.w = bmp.Width; //media.h = bmp.Height; //media.name = Const.MEDIA_VIEW_URL + "?id=" + filename; ////media.libelle = file.FileName; //media.content_type = "image/jpeg"; //lesMedias.Add(media); //Session[filename] = media; //string filename = Functions.Accent_to_Html(file.GetName().Replace(file.GetExtension(), "") + ".jpg"); //string filename = file.GetName().Replace(file.GetExtension(), "") + ".jpg"; //File.WriteAllBytes(Server.MapPath(PortalSettings.Current.HomeDirectory + _folder + "//" + filename), ms.GetBuffer()); FileManager.Instance.AddFile(FolderManager.Instance.GetFolder(_portalID, /*Const.IMG_PREFIX +*/ _folder), file.GetName(), file.InputStream /*ms*/); FolderManager.Instance.Synchronize(_portalID); //Functions.Log("fichier monté"); } //Session["lesmediasTEMP"] = lesMedias; //gvw_Photos.DataSource = lesMedias; //gvw_Photos.DataBind(); Gvw_Photos_Binding(); Panel0.Visible = true; //Panel1.Visible = true; Panel2.Visible = true; Panel3.Visible = false; } } catch (Exception ee) { Functions.Error(ee); //Session["lesmediasTEMP"] = null; gvw_Photos.DataSource = null; gvw_Photos.DataBind(); } }
/// <summary> /// Uploads files /// </summary> /// <param name="ID">ID of related work order</param> /// <param name="files">Files upload in work order</param> /// <param name="isRevision">Whether or not this is a revised file from the program manager</param> public static void UploadFiles(int ID, UploadedFileCollection files, bool isRevision) { // files are uploaded to a uploaded directory in subfolders of the ID number var destination = HttpContext.Current.Server.MapPath("~/uploads/" + ID + "/"); if (!System.IO.Directory.Exists(destination)) System.IO.Directory.CreateDirectory(destination); // let's file the files accordingly, then add an entry to the files table in the db foreach (UploadedFile file in files) { file.SaveAs(destination + file.FileName, true); WO.AddFile(ID, file.FileName, isRevision); } }
/// <summary> /// Uploads files /// </summary> /// <param name="ID">ID of related work order</param> /// <param name="files">Files uploaded in work order</param> public static void UploadFiles(int ID, UploadedFileCollection files) { UploadFiles(ID, files, false); }