net 上傳視頻

     [HttpPost]
        public ActionResult MultiUpload()
        {
            System.Web.HttpFileCollectionBase files = Request.Files;
            //for (var i = 2; i < files.Count; i++)
            HttpPostedFileBase postFile = files[1];
            string fileName = System.IO.Path.GetFileName(postFile.FileName);
            if (postFile != null)
            {
                if (postFile.ContentLength > 0)
                {
                    string filePath = postFile.FileName;
                    string filename2 = Guid.NewGuid().ToString();
                    string filename = filename2 + filePath.Substring(filePath.LastIndexOf('.'), filePath.Length - filePath.LastIndexOf('.'));
                    //設定上傳路徑(絕對路徑)
                    string upPath = Server.MapPath("~/") + AppConfig.UploadConfig.VideoFiles + "\\" + filename;
                    if (System.IO.File.Exists(upPath))
                    {
                        System.IO.File.Delete(upPath);
                    }
                    //文件上傳到絕對路徑                  
                    postFile.SaveAs(upPath);
                    string savePath = "\\" + AppConfig.UploadConfig.VideoFiles + "\\" + filename;
                }
            }
            return RedirectToAction("Index");
        }ide

相關文章
相關標籤/搜索