- public JsonResult File()
- {
- try
- {
- DirectoryInfo dir = System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory +
- @"\File");
- Stream files = Request.Files[0].InputStream;
- string path = dir.FullName + @"" + Request.Files[0].FileName;
- using (FileStream fs = new FileStream
- (path,FileMode.Append,FileAccess.Write,FileShare.ReadWrite))
- {
- byte[] buffer = new byte[512];
- long contentLength = files.Length;
- int length = files.Read(buffer, 0, buffer.Length);
- while (length > 0)
- {
- fs.Write(buffer, 0, length);
- buffer = new byte[512];
- length = files.Read(buffer, 0, buffer.Length);
- }
- fs.Flush();
- fs.Close();
- }
- return Json(new { success = true, message = path });
- }
- catch (Exception ex)
- {
- return Json(new { success = false, message = "error" });
- }
-
- }
复制代码
这个是网站接受到大文件上传,然后,写入到硬盘。
|