コード例 #1
0
 protected void lnkDownload_Click(object sender, EventArgs e)
 {
     try
     {
         LinkButton    lnkbtn           = (LinkButton)sender;
         string[]      values           = lnkbtn.CommandArgument.Split('&');
         AttachmentCls objAttachmentcls = new AttachmentCls();
         objAttachmentcls.IndexValue = values[2];
         DataTable    dt         = objAttachmentcls.GetPath();
         string       ServerPath = dt.Rows[0]["t_path"].ToString() + "\\" + values[0];// Server.MapPath("~/Files/") + values[0]; // "\\\\" + dt.Rows[0]["ServerName"].ToString() + dt.Rows[0]["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 (Exception ex)
     {
         //ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Some Technical issue Data Not Uploaded');", true);
     }
 }
コード例 #2
0
 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();
                         int nRecord = new Random(Guid.NewGuid().GetHashCode()).Next();
                         objAttachmentcls.RunningId  = nRecord;
                         objAttachmentcls.DocumentId = "AAA" + nRecord.ToString();
                         //DataTable dtDocID = objAttachmentcls.InsertAttachmentdata();
                         DataTable dtDocID = objAttachmentcls.InsertAttachmentdata();  //Change- 27-08-2018 Insert Attachment error related change
                         if (dtDocID.Rows.Count > 0)
                         {
                             PostedFile.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);
     }
 }
コード例 #3
0
 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);
     }
 }