Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
        //Testing for gitHub
        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)
                            {
                                double    filesize       = PostedFile.ContentLength;
                                DriveInfo dDrive         = new DriveInfo("D");
                                double    Availablespace = dDrive.AvailableFreeSpace;
                                if (filesize < Availablespace)
                                {
                                    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();
                                        int nRecord = new Random(Guid.NewGuid().GetHashCode()).Next();
                                        objAttachmentcls.RunningId  = nRecord;
                                        objAttachmentcls.DocumentId = "AAA" + nRecord.ToString();
                                        // DataTable dtFile = objAttachmentcls.GetFileName();
                                        //  if (dtFile.Rows.Count == 0)
                                        //  {
                                        //int nRecord = new Random(Guid.NewGuid().GetHashCode()).Next();
                                        //string sDocumentId = "AAA" + nRecord;
                                        //DataTable dtDocID = objAttachmentcls.Insertdata(nRecord, sDocumentId);
                                        //DataTable dtDocID = objAttachmentcls.Insertdata();
                                        DataTable dtDocID = objAttachmentcls.InsertAttachmentdata();
                                        if (dtDocID.Rows[0][0].ToString() != "0")
                                        {
                                            try
                                            {
                                                PostedFile.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
                                {
                                    ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Error: Not enough space on Disk! Contact IT Infrastructure Team.');", 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);
            }
        }