You are on page 1of 3

public void AddAttachment() { try { if (fupAttachment.HasFile) { DataTable dtblAttatch = new DataTable(); if (ViewState["temp"] == null) { dtblAttatch.Columns.Add("attachmentName"); dtblAttatch.Columns.

Add("fileName"); } else { dtblAttatch = (DataTable)ViewState["temp"]; } int inFolderCount = Directory.GetFiles(Server.MapPath("~/Attachm ent/Quotation/Temp/")).Length; AttachFile(inFolderCount); DataRow drow = dtblAttatch.NewRow(); drow["attachmentName"] = ViewState["attachmentName"].ToString(); drow["fileName"] = ViewState["fileName"].ToString(); dtblAttatch.Rows.Add(drow); gvAttachment.Visible = true; gvAttachment.Columns[1].Visible = true; gvAttachment.DataSource = dtblAttatch; gvAttachment.DataBind(); gvAttachment.Columns[1].Visible = false; ViewState["temp"] = dtblAttatch; //lbtnUpload.Enabled = false; fupAttachment.Enabled = false; } } catch { //MessageBox(ex.ToString()); } } public void AttachmentDelete(int inRowIndex) { try { DataTable dtAttchmt = (DataTable)ViewState["temp"]; for (int i = dtAttchmt.Rows.Count - 1; i >= 0; i--) { DataRow dr = dtAttchmt.Rows[i]; if (dr.ItemArray[0].ToString() == gvAttachment.Rows[inRowIndex]. Cells[1].Text) { dtAttchmt.Rows.Remove(dr); string strDestinationPath = Server.MapPath("~/Attachment/Quo tation/Temp/"); System.IO.File.Delete(strDestinationPath + gvAttachment.Rows [inRowIndex].Cells[1].Text); }

} gvAttachment.Columns[1].Visible = true; gvAttachment.DataSource = dtAttchmt; gvAttachment.DataBind(); gvAttachment.Columns[1].Visible = false; ViewState["temp"] = dtAttchmt; //lbtnUpload.Enabled = true; fupAttachment.Enabled = true; } catch { //MessageBox(ex.ToString()); } } public void AttachmentMoveToFolder() { try { DataTable dtblQuotation = new DataTable(); QuotationOrBillSP quotOrBillSP = new QuotationOrBillSP(); dtblQuotation = quotOrBillSP.QuotationOrBillViewbyserialNo(decimal.P arse(txtQuotationNo.Text)); DataTable dtbl = new DataTable(); dtbl = (DataTable)ViewState["temp"]; if (dtbl != null) { string strPathDestination = Server.MapPath("~/Attachment/Quotati on/"); string strPathSource = Server.MapPath("~/Attachment/Quotation/Te mp/"); string strAttachmentName = dtbl.Rows[0].ItemArray[0].ToString(); string strExtension = Path.GetExtension(strAttachmentName); int inFolderCount = Directory.GetFiles(Server.MapPath("~/Attachm ent/Quotation/")).Length; inFolderCount = inFolderCount + 2; string strnewfilename = inFolderCount + strExtension; if (System.IO.File.Exists(strPathSource + strAttachmentName)) { if (dtblQuotation.Rows.Count > 0) { string strAttName = dtblQuotation.Rows[0].ItemArray[5].T oString(); if (System.IO.File.Exists(strPathDestination + strAttNam e)) { System.IO.File.Delete(strPathDestination + strAttNam e); strnewfilename = strAttName; } } ViewState["attachmentName"] = strnewfilename; System.IO.File.Move(strPathSource + strAttachmentName, strPa thDestination + strnewfilename); System.IO.File.Delete(strPathSource + strAttachmentName); } } }

catch { //MessageBox(ex.ToString()); } }

You might also like