Exemple #1
0
        private bool UploadMain()
        {
            if (FileUpload1.HasFile)
            {
                string folderPath = Server.MapPath("~/EXCEL/");
                //Check whether Directory (Folder) exists.
                if (!Directory.Exists(folderPath))
                {
                    //If Directory (Folder) does not exists. Create it.
                    Directory.CreateDirectory(folderPath);
                }

                FileUpload fu                = FileUpload1;
                String     fileExtension     = System.IO.Path.GetExtension(fu.FileName).ToLower();
                String[]   allowedExtensions = { ".xlsx" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        try
                        {
                            string    job_id;
                            ClsModule mdl = new ClsModule();
                            job_id = mdl.getRuningNoDoc();


                            //Doc.doc_name = fu.FileName;
                            //Doc.create_by = Session["NAME"].ToString();
                            //Doc.secure_prepare = Session["EMAIL"].ToString();
                            //Doc.attach_file_name = Doc.doc_id + ".zip";
                            //Doc.content = Content.Text;


                            string s_newfilename = job_id + fileExtension;
                            fu.PostedFile.SaveAs(folderPath + s_newfilename);


                            ClsModule obj = new ClsModule();


                            MODEL.Log      L   = new MODEL.Log();
                            Helper.Utility Log = new Helper.Utility();

                            L.ip        = obj.GetIPAddress();
                            L.page      = obj.getPageName();
                            L.content   = "Upload success.";
                            L.create_by = "";    // Session["EMAIL"].ToString();

                            Log.WriteLog(L);


                            ReadExcel(job_id);

                            genBarcode(job_id);

                            Response.Redirect("DataJob.aspx");

                            //    lblMessage.Text = Path.GetFileName(FileUpload1.FileName) + " has been uploaded.";
                            //imagepath = ImageSavedPath + s_newfilename;
                            return(true);
                        }
                        catch (Exception ex)
                        {
                            Response.Write("File could not be uploaded." + ex.Message);
                            return(false);
                        }
                    }
                    else
                    {
                        Response.Write("Please upload xlsx file only.");
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                Response.Write("<script>alert('โปรดเลือกไฟล์ก่อน');</script>");
                return(false);
            }
        }