/// <summary>
        /// Upload............
        /// </summary>
        /// <param name="dicPostedFiles"></param>
        private void StartUpload(Dictionary<string, HttpPostedFile> dicPostedFiles)
        {
            string EmailCustomer = "";
            string EmailMember = "";
            string listName = "";

            #region Upload file
            if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
            {
                BlobManager blobManager = new BlobManager();
                foreach (string fileName in dicPostedFiles.Keys)
                {
                    HttpPostedFile postedFile = dicPostedFiles[fileName];
                    long ContentLength = 0;
                    if (postedFile == null)
                    {
                        ContentLength = blobManager.CopyBlob("Temp/" + HiddenFieldAccount.Value + "/" +  fileName, LabelCustomerName.Text + "/" + fileName);
                    }
                    else
                    {
                        ContentLength = postedFile.ContentLength;
                        blobManager.UploadFromStream(postedFile.InputStream, LabelCustomerName.Text + "/" + fileName);
                    }

                    listName += fileName + ", ";
                    FileInfoMation obj = new FileInfoMation();
                    obj.File_Sharing_ID = HiddenFieldID.Value;
                    obj.File_Name = Path.GetFileName(fileName);
                    obj.File_Size = ContentLength.ToString();
                    obj.Upload_Date = DateTime.Now.ToString();
                    FileInforMa.File_Insert(obj);
                }
            }
            else
            {
                foreach (HttpPostedFile postedFile in dicPostedFiles.Values)
                {
                    CreateFolder();
                    string directoryPath = Server.MapPath("~/" + Constant.UPLOAD_STORAGE + "\\" + LabelCustomerName.Text.Trim());
                    postedFile.SaveAs(directoryPath + "\\" + Path.GetFileName(postedFile.FileName));

                    listName += Path.GetFileName(postedFile.FileName) + ", ";
                    FileInfoMation obj = new FileInfoMation();
                    obj.File_Sharing_ID = HiddenFieldID.Value;
                    obj.File_Name = Path.GetFileName(postedFile.FileName);
                    obj.File_Size = postedFile.ContentLength.ToString();
                    obj.Upload_Date = DateTime.Now.ToString();
                    FileInforMa.File_Insert(obj);
                }

            }
            #endregion

            #region SendMail
            if (!string.IsNullOrEmpty(listName))
            {
                listName = listName.Remove(listName.Length - 2);
                ///// send mail customer
                List<CustomerInfo> listCustomer = new List<CustomerInfo>();
                listCustomer = CustomerCallControl.File_GetByAll();
                listCustomer = listCustomer.Where(c => c.File_Sharing_ID == HiddenFieldID.Value).ToList();
                EmailCustomer = listCustomer[0].CustomerEmail;

                UserMail mailSystemCus = new UserMail(HiddenFieldAccount.Value, HiddenFieldAccount.Value, EmailCustomer);
                mailSystemCus.AddParams("{FileName}", listName);
                string mailBody = GetMailBody("Alert_mail_upload.txt");
                mailSystemCus.SendEmail(mailSystemCus, Common.GetResourceString("MAIL_UploadSubject"), mailBody);

                ///// send mail member
                List<DDMemberInfoCustomer> listMemberAccount = new List<DDMemberInfoCustomer>();
                listMemberAccount = DDMemberCallControlCustomer.File_GetByAll();
                listMemberAccount = listMemberAccount.Where(c => c.Account == HiddenFieldAccount.Value).ToList();
                EmailMember = listMemberAccount[0].Email;

                UserMail mailSystemMem = new UserMail(HiddenFieldAccount.Value, HiddenFieldAccount.Value, EmailMember);
                mailSystemMem.AddParams("{FileName}", listName);
                mailSystemMem.SendEmail(mailSystemMem, Common.GetResourceString("MAIL_UploadSubject"), mailBody);
                PostedFiles = new Dictionary<string, HttpPostedFile>();
                RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("TITLE_SUCESS"), GetResource("MSG_UPLOAD_SUCESS")) + "\");");
            }
            else
                throw new Exception(GetResource("MSG_AT_LEAST_ONE_CUSTOMER"));
            #endregion
        }
        /// <summary>
        /// Download webserver
        /// </summary>
        protected void DownloadWebServer()
        {
            string fileName = "";
            string filePath = "";
            string listName = "";
            List<String> names = new List<String>();
            string Email = "";
            string customerFoler = "";
            ZipFile zip = new ZipFile();
            //Get name
            customerFoler = Server.MapPath("~/" + Constant.UPLOAD_STORAGE) + "\\" + LabelCustomerName.Text;
            for (int i = 0; i < CheckBoxListFile.Items.Count; i++)
            {
                if (CheckBoxListFile.Items[i].Selected)
                {
                    fileName = CheckBoxListFile.Items[i].ToString();
                    listName += fileName + ", ";
                    names.Add(fileName);
                }
            }
            // Send Mail and download
            if (!string.IsNullOrEmpty(listName))
            {
                //Send Mail
                List<DDMemberInfoCustomer> listMemberAccount = new List<DDMemberInfoCustomer>();
                listMemberAccount = DDMemberCallControlCustomer.File_GetByAll();
                listMemberAccount = listMemberAccount.Where(c => c.Account == HiddenFieldAcount.Value).ToList();
                Email = listMemberAccount[0].Email;

                UserMail mailSystem = new UserMail("A", "A", Email);
                listName = listName.Remove(listName.Length - 2);
                mailSystem.AddParams("{FileName}", listName);
                string mailBody = GetMailBody("Alert_mail_download.txt");
                mailSystem.SendEmail(mailSystem, "Download Notice", mailBody);

                //Zip file
                foreach(string namenew in names)
                {
                    filePath = string.Format("{0}\\{1}", customerFoler, namenew);
                    if (!File.Exists(filePath))
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_FILE_DOWNLOAD_FOUND") + "');", true);
                        return;
                    }
                    else if(names.Count > 1)
                        zip.AddFile(filePath, LabelCustomerName.Text + GetResource("All_Files"));
                    else
                        zip.AddFile(filePath, namenew);
                }
                //Download
                ButtonDownload.Enabled = true;
                logger.Info("start");
                Response.Clear();
                Response.BufferOutput = false;
                Response.ContentType = "application/zip";
                if (names.Count > 1)
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + LabelCustomerName.Text + GetResource("All_Files") + ".zip");
                else
                {
                    fileName = fileName.Remove(fileName.Length - 4);
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");
                }
                zip.Save(Response.OutputStream);
                Response.End();
                logger.Info("end");
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_AT_LEST_ONE_FILE_DOWNLOAD") + "');", true);
                return;
            }
        }
        /// <summary>
        /// Download Azure
        /// </summary>
        protected void DownloadAzure()
        {
            string fileName = "";
            string listName = "";
            List<String> names = new List<String>();
            string Email = "";
            ZipFile zip = new ZipFile();

            // Get Name
            for (int i = 0; i < CheckBoxListFile.Items.Count; i++)
            {
                if (CheckBoxListFile.Items[i].Selected)
                {
                    fileName = CheckBoxListFile.Items[i].ToString();
                    listName += fileName + ", ";
                    names.Add(fileName);
                }
            }
            //Send Mail And download
            if (!string.IsNullOrEmpty(listName))
            {
                //Send Mail
                try
                {
                    List<DDMemberInfoCustomer> listMemberAccount = new List<DDMemberInfoCustomer>();
                    listMemberAccount = DDMemberCallControlCustomer.File_GetByAll();
                    listMemberAccount = listMemberAccount.Where(c => c.Account == HiddenFieldAcount.Value).ToList();
                    Email = listMemberAccount[0].Email;

                    UserMail mailSystem = new UserMail(HiddenFieldAcount.Value, HiddenFieldAcount.Value, Email);
                    var listNamenew = listName.Remove(listName.Length - 2);
                    mailSystem.AddParams("{FileName}", listNamenew);
                    string mailBody = GetMailBody("Alert_mail_download.txt");

                    mailSystem.SendEmail(mailSystem, Common.GetResourceString("MAIL_DownloadSubject"), mailBody);
                }
                catch
                {

                }

                // Download
                BlobManager blobManager = new BlobManager();
                foreach (string namenew in names)
                {

                    WebClient client = new WebClient();
                    var s = client.OpenRead(blobManager.GetURi(LabelCustomerName.Text  + "/" + namenew));
                    zip.MaxOutputSegmentSize = 1024 * 1024 * 1024;
                    zip.AddEntry(namenew, s);
                }

                ButtonDownload.Enabled = true;
                Response.Clear();
                Response.Buffer = false;
                Response.BufferOutput = false;
                Response.ContentType = "application/zip";
                if (names.Count > 1)
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + LabelCustomerName.Text + GetResource("All_Files") + ".zip");
                else
                {
                    fileName = fileName.Remove(fileName.Length - 4);
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");
                }
                Response.Flush();
                zip.Save(Response.OutputStream);
               Response.End();
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_AT_LEST_ONE_FILE_DOWNLOAD") + "');", true);
                return;
            }
        }
예제 #4
0
        protected void downloadFile(string fName)
        {
            try
            {
                string fileName = "";
                string filePath = "";
                string listName = "";
                List<String> names = new List<String>();
                string Email = "";

                ZipFile zip = new ZipFile();
                if (fName == null)
                {
                    foreach (GridViewRow row in fileGrid.Rows)
                    {
                        fileName = row.Cells[2].Text;
                        listName += fileName + ", ";
                        names.Add(fileName);
                    }
                }
                else
                {
                    fileName = fName;
                    listName += fileName + ", ";
                    names.Add(fileName);
                }
                #region User Azure
                if (Common.AppSettingKey(Constant.STORAGE_CONNECT_STRING) != "")
                {
                    // Send Mail
                    foreach( GridViewRow row in gridCustomers.Rows)
                    {
                        Email = row.Cells[1].Text;
                    }

                    UserMail mailSystem = new UserMail("A", "A", Email);
                    var listNamenew = listName.Remove(listName.Length - 2);
                    mailSystem.AddParams("{FileName}", listNamenew);
                    string mailBody = GetMailBody("Alert_mail_download.txt");
                    mailSystem.SendEmail(mailSystem, "Download Notice", mailBody);

                    // Download
                    BlobManager blobManager = new BlobManager();
                    foreach (string namenew in names)
                    {
                        WebClient client = new WebClient();
                        var s = client.OpenRead(blobManager.GetURi(LabelCustomerName.Text + "/" + namenew));
                        zip.AddEntry(namenew, s);
                    }
                    Response.Clear();
                    Response.ContentType = "application/zip";
                    if(names.Count > 1)
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + LabelCustomerName.Text + GetResource("All_Files") + ".zip");
                    else
                        Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");
                    zip.Save(Response.OutputStream);
                    Response.End();
                }
                #endregion

                #region User WebServer
                else
                {
                    string customerFoler = Server.MapPath("~/" + Constant.UPLOAD_STORAGE) + "\\" + LabelCustomerName.Text;
                    foreach(string NameNew in names)
                    {
                        filePath = string.Format("{0}\\{1}", customerFoler, NameNew);
                        if (!File.Exists(filePath))
                        {
                            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_FILE_DOWNLOAD_FOUND") + "');", true);
                            return;
                        }
                        if (names.Count > 1)
                            zip.AddFile(filePath, LabelCustomerName.Text + GetResource("All_Files"));
                        else
                            zip.AddFile(filePath, NameNew);
                    }
                    if (!string.IsNullOrEmpty(listName))
                    {
                        foreach (GridViewRow row in gridCustomers.Rows)
                        {
                            Email += row.Cells[1].Text + ";";
                        }
                        Email = Email.Substring(0, Email.Length - 1);
                        UserMail mailSystem = new UserMail("A", "A", Email);
                        listName = listName.Remove(listName.Length - 2);
                        mailSystem.AddParams("{FileName}", listName);
                        string mailBody = GetMailBody("Alert_mail_download.txt");
                        mailSystem.SendEmail(mailSystem, "Download Notice", mailBody);

                        Response.Clear();
                        Response.ContentType = "application/zip";
                        if(names.Count > 1)
                            Response.AddHeader("Content-Disposition", "attachment; filename=" + LabelCustomerName.Text + GetResource("All_Files") + ".zip");
                        else
                            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip");
                        zip.Save(Response.OutputStream);
                        Response.End();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + GetResource("MSG_AT_LEST_ONE_FILE_DOWNLOAD") + "');", true);
                        return;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("TITLE_ERROR"), ex.Message) + "\");");
                return ;
            }
        }