Page 151 - ระบบสารสนเทศเพื่อการบริหารจัดการเอกสารอิเล็กทรอนิกส์ (e-Document)
P. 151

ห้องสมุดกรมพัฒนาที่ดิน
                                                                                                        ค- 38




                                  string sFileName; //ชื่อไฟล์ abc.txt
                                  string sFileExt; //ชนิดไฟล์ .txt

                                  sFileName = upBrowse.FileName;
                                  sFileExt = Path.GetExtension(sFileName).ToLower();
                                  #region Check bValidExt (failure => terminate program)
                                  bValidExt = false;

                                  for (int i = 0; i < sValidExt.Length; i++)
                                  {
                                      sAlertInvalidFileType += " " + sValidExt[i];

                                      if (sValidExt[i] == sFileExt)
                                      {
                                          bValidExt = true;
                                      }
                                  }

                                  if (bValidExt == false)
                                  {
                                      return sAlertInvalidFileType;
                                  }
                                  #endregion

                                  #region Check file size (optional)
                                  if (upBrowse.PostedFile.ContentLength > 3145728)
                                  {
                                      return "ไม่สามารถแนบไฟล์ที่มีขนาดเกินกว่า 3 MB ได้";
                                  }
                                  #endregion

                                  #region Change name of uploaded file (optional)
                                  sFileName = sFilename + sFileExt;
                                  #endregion

                                  string sCurrentPath = Server.MapPath("~/" + sFolderName +
                  "/");

                                  if (upBrowse.HasFile)
                                  {
                                      sCurrentPath += sFileName;
                                      upBrowse.SaveAs(sCurrentPath);

                                      return "y" + sFileExt;
                                  }
                                  else
                                  {
                                      return sAlertFailure;
                                  }
                              }
                              catch (Exception ex)
                              {
                                  return "ไม่สามารถอัพโหลดไฟล์ได้ เนื่องจาก" + ex.Message;
                              }
                          }
                      }

                      protected void btnSave_Click(object sender, EventArgs e)
   146   147   148   149   150   151   152   153   154   155   156