protected void lnkDownload_Click(object sender, EventArgs e)
 {
     try
     {
         LinkButton lnkbtn = (LinkButton)sender;
         string[]   values = lnkbtn.CommandArgument.Split('@');
         objProjectCls = new ProjectClass();
         objProjectCls.AttachmentHandle = "T_ERECTIONACTIVITY";
         DataTable dt         = objProjectCls.GetPath();
         string    ServerPath = "D:\\" + dt.Rows[0]["t_path"].ToString() + "\\";
         // string ServerPath = "D:\\" + dt.Rows[0]["t_serv"].ToString() + "\\" + dt.Rows[0]["t_path"].ToString() + "\\" + values[0];// dt.Rows[0]["Path"].ToString() + "\\" + values[0];// Server.MapPath("~/Files/") + values[0]; //
         //string ServerPath = "E:\\attachmentlibrary1\\" + values[0];
         //"D:\\" + dt.Rows[0]["t_path"].ToString() + "\\" + values[0];
         WebClient    req      = new WebClient();
         HttpResponse response = HttpContext.Current.Response;
         response.Clear();
         response.ClearContent();
         response.ClearHeaders();
         response.Buffer = true;
         response.AddHeader("Content-Disposition", "attachment;filename=\"" + values[1] + "\"");
         byte[] data = req.DownloadData(ServerPath);
         response.BinaryWrite(data);
         response.End();
     }
     catch (System.Exception ex)
     {
         ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Data Could not find');", true);
     }
 }
        protected void UploadAttachment(string NotesId)
        {
            try
            {
                string sUsername = (string)(Session["Username"]);
                // sUsername = "******";// for testing only
                //if (Request.QueryString["user"] != null)
                if (sUsername != null)
                {
                    objProjectCls = new ProjectClass();
                    // objProjectCls.IndexValue = Request.QueryString["Index"];
                    objProjectCls.AttachmentHandle = "T_ERECTIONACTIVITY";
                    DataTable dt = objProjectCls.GetPath();
                    if (dt.Rows.Count > 0)
                    {
                        //string ServerPath =  dt.Rows[0]["t_serv"].ToString() + "\\"+ "D:\\"  + dt.Rows[0]["t_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/");//
                                                                                             //attachmentlibrary1
                                                                                             //  string ServerPath = "E:\\attachmentlibrary1\\";
                        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
                                    {
                                        objProjectCls = new ProjectClass();
                                        objProjectCls.AttachmentHandle = "T_ERECTIONACTIVITY";
                                        objProjectCls.IndexValue       = NotesId;
                                        objProjectCls.PurposeCode      = "Attachment for Mobile App Notes";// Request.QueryString["PurposeCode"];

                                        //objProjectCls.AttachedBy = Request.QueryString["user"];
                                        objProjectCls.AttachedBy  = sUsername;
                                        objProjectCls.FileName    = fileName + fileExtension;
                                        objProjectCls.LibraryCode = dt.Rows[0]["LibCode"].ToString();
                                        //"LIB000001";
                                        // DataTable dtFile = objProjectCls.GetFileName();
                                        //  if (dtFile.Rows.Count == 0)
                                        //  {
                                        DataTable dtDocID = objProjectCls.InsertAttachment();
                                        if (dtDocID.Rows[0][0].ToString() != "0")
                                        {
                                            try
                                            {
                                                string AttachServerPath = ServerPath + dtDocID.Rows[0][0];
                                                FileUpload.SaveAs(AttachServerPath);
                                            }
                                            catch (Exception ex)
                                            {
                                                // err.Text = ex.Message;
                                            }
                                            // FileUpload.SaveAs(LocalPath + fileName + fileExtension);
                                            HttpContext.Current.Cache.Remove("ATHData");
                                            //AttachmentBindData(NotesId);
                                            BindData();
                                            ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Successfully Uploaded');", true);
                                        }
                                        else
                                        {
                                            //objProjectCls = new AttachmentCls();
                                            //objProjectCls.DocumentId = dtDocID.Rows[0][0].ToString();
                                            //int res = objProjectCls.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);
                }
            }
            catch (Exception ex)
            {
            }
        }