protected void AjaxFileUploadInsertImage_OnUploadComplete(object sender, AjaxFileUploadEventArgs file) { Byte[] fileBytes = file.GetContents(); string sPath = Server.MapPath("/" + ConfigurationManager.AppSettings["QMSDBPath"] + "/"); string FileName = "QMSDB_" + Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); string FullFilename = Path.Combine(sPath, FileName); FileStream fileStream = new FileStream(FullFilename, FileMode.Create, FileAccess.ReadWrite); fileStream.Write(fileBytes, 0, fileBytes.Length); fileStream.Close(); BLL_QMSDB_ProcedureSection.Ins_Procedure_Attachment(Convert.ToInt32(Request.QueryString["PROCEDURE_ID"]), FileName, Convert.ToInt32(Session["userid"])); Session["UploadedFiles_Name"] += FileName + ","; }
protected void btnInsertPic_Click(object sender, EventArgs e) { try { if (Request.Files.Count > 0 && txtProcedureSectionDetails.ActiveMode == AjaxControlToolkit.HTMLEditor.ActiveModeType.Design) { //string sPath = Server.MapPath("/" + ConfigurationManager.AppSettings["QMSDBPath"] + "/"); try { int Max_Height = 400; int Max_Width = 400; System.Text.StringBuilder size = new System.Text.StringBuilder(); string sPath = Server.MapPath("/" + ConfigurationManager.AppSettings["QMSDBPath"] + "/"); for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFile postedFile = Request.Files[i]; string FileName = "QMSDB_" + Guid.NewGuid().ToString() + Path.GetExtension(postedFile.FileName); string FullFilename = Path.Combine(sPath, FileName); postedFile.SaveAs(FullFilename); //FileStream fileStream = new FileStream(FullFilename, FileMode.Create, FileAccess.ReadWrite); //fileStream.Write(fileBytes, 0, fileBytes.Length); //fileStream.Close(); BLL_QMSDB_ProcedureSection.Ins_Procedure_Attachment(Convert.ToInt32(Request.QueryString["PROCEDURE_ID"]), FileName, Convert.ToInt32(Session["userid"])); if (postedFile.ContentLength > 0) { if (!string.IsNullOrWhiteSpace(postedFile.FileName)) { System.Drawing.Image objUpdImg = System.Drawing.Image.FromFile(Path.Combine(sPath, FileName)); if (objUpdImg.Height > Max_Height) { size.Append("height:" + Max_Height.ToString() + "px;"); } if (objUpdImg.Width > Max_Width) { size.Append("width:" + Max_Width.ToString() + "px;"); } txtProcedureSectionDetails.Content += "<img style='" + size.ToString() + "' src='/" + ConfigurationManager.AppSettings["QMSDBPath"] + "/" + FileName + "'>"; size.Clear(); } } } } catch { } finally { //updInserImage.Update(); Session["UploadedFiles_Name"] = ""; } //Byte[] fileBytes = file.GetContents(); //string sPath = Server.MapPath("/" + ConfigurationManager.AppSettings["QMSDBPath"] + "/"); //string FileName = "QMSDB_" + Guid.NewGuid().ToString() + Path.GetExtension(file.FileName); //string FullFilename = Path.Combine(sPath, FileName); //FileStream fileStream = new FileStream(FullFilename, FileMode.Create, FileAccess.ReadWrite); //fileStream.Write(fileBytes, 0, fileBytes.Length); //fileStream.Close(); //BLL_QMSDB_ProcedureSection.Ins_Procedure_Attachment(Convert.ToInt32(Request.QueryString["PROCEDURE_ID"]), FileName, Convert.ToInt32(Session["userid"])); //Session["UploadedFiles_Name"] += FileName + ","; //Guid gFileName = PhoenixCommonFileAttachment.InsertAttachment(Request.Files, new Guid(ViewState["dtkey"].ToString()), PhoenixModule.PURCHASE, null, ".jpg,.png,.gif"); //DataTable dt = PhoenixCommonFileAttachment.AttachmentList(new Guid(ViewState["dtkey"].ToString())); //DataRow[] dr = dt.Select("FLDDTKEY = '" + gFileName.ToString() + "'"); //if (dr.Length > 0) // txtItemDetails.Content = txtItemDetails.Content + "<img src=\"" + HttpContext.Current.Session["sitepath"] + "/attachments/" + dr[0]["FLDFILEPATH"].ToString() + "\" />"; } else { //ucError.Text = Request.Files.Count > 0 ? "You are not in design mode" : "No Picture selected."; //ucError.Visible = true; } } catch (Exception ex) { //ucError.ErrorMessage = ex.Message; //ucError.Visible = true; } }