protected void btnUpload_Click(object sender, EventArgs e) { if (ddlHandle.SelectedValue != "Select" && ddlIndex.SelectedValue != "") { objAttachmentcls = new AttachmentCls(); objAttachmentcls.IndexValue = ddlIndex.SelectedValue; // Request.QueryString["Index"]; DataTable dt = objAttachmentcls.GetPath(); string ServerPath = dt.Rows[0]["Path"].ToString() + "\\"; // "\\\\" + dt.Rows[0]["ServerName"].ToString() + "\\" + dt.Rows[0]["Path"].ToString() + "\\"; // Server.MapPath("~/Files/");// if (FileUpload.HasFile) { int filecount = 0; filecount = FileUpload.PostedFiles.Count(); if (filecount > 0) { foreach (HttpPostedFile PostedFile in FileUpload.PostedFiles) { string fileName = Path.GetFileNameWithoutExtension(PostedFile.FileName); string fileExtension = Path.GetExtension(PostedFile.FileName); try { AttachmentCls objAttachmentcls = new AttachmentCls(); objAttachmentcls.AttachmentHandle = ddlHandle.SelectedValue; // Request.QueryString["AthHandle"]; objAttachmentcls.IndexValue = ddlIndex.SelectedValue; // Request.QueryString["Index"]; objAttachmentcls.PurposeCode = ddlPurpose.SelectedValue; // Request.QueryString["PurposeCode"]; objAttachmentcls.AttachedBy = "0"; //Request.QueryString["AttachedBy"]; objAttachmentcls.FileName = fileName + fileExtension; objAttachmentcls.LibraryCode = dt.Rows[0]["LibCode"].ToString(); DataTable dtDocID = objAttachmentcls.Insertdata(); if (dtDocID.Rows.Count > 0) { FileUpload.SaveAs(ServerPath + dtDocID.Rows[0][0]); ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Successfully Uploaded');", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('" + ex.Message + "');", true); } } } } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Please select all fields');", true); } }
protected void btnUpload_Click(object sender, EventArgs e) { if (Request.QueryString["AthHandle"] != null && Request.QueryString["Index"] != null && Request.QueryString["AttachedBy"] != null) { objAttachmentcls = new AttachmentCls(); // objAttachmentcls.IndexValue = Request.QueryString["Index"]; objAttachmentcls.AttachmentHandle = Request.QueryString["AthHandle"]; DataTable dt = objAttachmentcls.GetPath(); if (dt.Rows.Count > 0) { //string ServerPath = "\\\\" + dt.Rows[0]["ServerName"].ToString() + "\\" + dt.Rows[0]["Path"].ToString() + "\\"; //dt.Rows[0]["Path"].ToString() + "\\";// // Server.MapPath("~/Files/");// string ServerPath = "D:\\" + dt.Rows[0]["t_path"].ToString() + "\\"; //dt.Rows[0]["Path"].ToString() + "\\";// // Server.MapPath("~/Files/");// string LocalPath = Server.MapPath("~/Files/"); if (FileUpload.HasFile) { int filecount = 0; filecount = FileUpload.PostedFiles.Count(); if (filecount > 0) { foreach (HttpPostedFile PostedFile in FileUpload.PostedFiles) { string fileName = Path.GetFileNameWithoutExtension(PostedFile.FileName); string fileExtension = Path.GetExtension(PostedFile.FileName); try { AttachmentCls objAttachmentcls = new AttachmentCls(); objAttachmentcls.AttachmentHandle = Request.QueryString["AthHandle"]; objAttachmentcls.IndexValue = Request.QueryString["Index"]; objAttachmentcls.PurposeCode = "Dmisg134_1_vendor";// Request.QueryString["PurposeCode"]; objAttachmentcls.AttachedBy = Request.QueryString["AttachedBy"]; objAttachmentcls.FileName = fileName + fileExtension; objAttachmentcls.LibraryCode = dt.Rows[0]["LibCode"].ToString(); // DataTable dtFile = objAttachmentcls.GetFileName(); // if (dtFile.Rows.Count == 0) // { DataTable dtDocID = objAttachmentcls.Insertdata(); if (dtDocID.Rows[0][0].ToString() != "0") { try { FileUpload.SaveAs(ServerPath + dtDocID.Rows[0][0]); } catch (Exception ex) {// err.Text = ex.Message; } // FileUpload.SaveAs(LocalPath + fileName + fileExtension); HttpContext.Current.Cache.Remove("ATHData"); BindData(); ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Successfully Uploaded');", true); } else { //objAttachmentcls = new AttachmentCls(); //objAttachmentcls.DocumentId = dtDocID.Rows[0][0].ToString(); //int res = objAttachmentcls.DeleteAttachment(); ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Attachment Handle does not exist');", true); } // } // else // { // ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('This file name already exist please change your file name');", true); // } } catch (System.Exception ex) { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('" + ex.Message + "');", true); } } } else { } } else { } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Attachment Handle does not exist');", true); } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Data not found Properly');", true); } }