Ejemplo n.º 1
0
        public ActionResult UploadA(string CustId, string YY, string Kind, int limitCount, HttpPostedFileBase fileName)
        {
            UpFileResult r = new UpFileResult();

            //Log.Write(fileName.ContentLength.ToString());
            //Log.WriteToFile();
            try
            {
                int size = 1024 * 1024 * 38;

                if (fileName.ContentLength > size)
                {
                    r.result = false;
                    r.message = "檔案太大,需小於38MB!";
                }

                string path = "~/Upload/" + YY + "/" + CustId + "/" + Kind + "/";
                string spath = Server.MapPath(path);
                if (!System.IO.Directory.Exists(spath))
                {
                    System.IO.Directory.CreateDirectory(spath);
                }
                else {
                    var files = System.IO.Directory.GetFiles(spath);
                    if (files.Length >= limitCount)
                    {
                        //r.result = false;
                        //r.message = "檔案數量超過限制:" + limitCount;
                        return RedirectToAction("UpLoadFormA",
                            new { CustId = CustId, YY = YY, Kind = Kind, limitCount = limitCount, message = "檔案數量超過限制:" + limitCount });
                    }
                }

                fileName.SaveAs(spath + fileName.FileName);
                r.result = true;
            }
            catch (Exception ex)
            {
                return RedirectToAction("UpLoadFormA",
                    new { CustId = CustId, YY = YY, Kind = Kind, limitCount = limitCount, message = ex.Message });
            }
            return RedirectToAction("UpLoadFormA", new { CustId = CustId, YY = YY, Kind = Kind, limitCount = limitCount });
        }
Ejemplo n.º 2
0
        public string aj_FUpload(string CustId, string YY, string Kind, int limitCount, HttpPostedFileWrapper fileName)
        {
            UpFileResult r = new UpFileResult();

            //Log.Write(fileName.ContentLength.ToString());
            //Log.WriteToFile();
            try
            {
                int size = 1024 * 1024 * 38;

                if (fileName.ContentLength > size)
                {
                    r.result = false;
                    r.message = "檔案太大,需小於38MB!";
                    return defJSON(r);
                }

                string path = "~/Upload/" + YY + "/" + CustId + "/" + Kind + "/";
                string spath = Server.MapPath(path);
                if (!System.IO.Directory.Exists(spath))
                {
                    System.IO.Directory.CreateDirectory(spath);
                }
                else {
                    var files = System.IO.Directory.GetFiles(spath);
                    if (files.Length >= limitCount)
                    {
                        r.result = false;
                        r.message = "檔案數量超過限制:" + limitCount;
                        return defJSON(r);
                    }
                }

                fileName.SaveAs(spath + fileName.FileName);
                r.result = true;
            }
            catch (Exception ex)
            {

                r.result = false;
                r.message = ex.Message;
            }
            return defJSON(r);
        }