コード例 #1
0
        /**
         * save file using kendo file uploader
         * menangani kalau nama file sama
         * The Name of the Upload component is "files"
         * currently not support multiple uploads
         *
         * @return filepath ex "~/Uploads/rekadia.jpg"
         */
        public string Save(IEnumerable<HttpPostedFileBase> files)
        {
            //kamus lokal
            string fileName = "", savedFilename = "", physicalPath = "", imagePath = "", friendlyFilename = "";

            //algoritma
            if (files != null)
            {
                foreach (var file in files)
                {
                    var identifier = Guid.NewGuid();
                    bool fileDirectory = Directory.Exists(Server.MapPath(FILE_DIRECTORY));
                    if (fileDirectory == false)
                    {
                        Directory.CreateDirectory(Server.MapPath(FILE_DIRECTORY));
                    }
                    fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    friendlyFilename = new DisplayFormatHelper().URLFriendly(fileName) + Path.GetExtension(file.FileName);
                    savedFilename = identifier + "_" + friendlyFilename;

                    //save file
                    physicalPath = Path.Combine(Server.MapPath(FILE_DIRECTORY), savedFilename);
                    file.SaveAs(physicalPath);
                }
            }

            imagePath = FILE_DIRECTORY + savedFilename;
            return new JavaScriptSerializer().Serialize(new { filepath = imagePath, filename = friendlyFilename, absolutepath = VirtualPathUtility.ToAbsolute(imagePath) });
        }
コード例 #2
0
        public ActionResult Download()
        {
            DisplayFormatHelper dfh = new DisplayFormatHelper();
            List<log> logs = RepoLog.Find();
            LogPresentationStub stub = new LogPresentationStub();
            MemoryStream ms = stub.GenerateExcel(stub.MapList(logs));
            string filename = string.Format("log {0}.xlsx", DateTime.Now.ToString(dfh.SqlDateFormat));

            return File(ms.ToArray(), "application/vns.ms-excel", filename);
        }