Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. [AcceptVerbs(HttpVerbs.Post)]
  2.         public ActionResult UploadStreamLogFile()
  3.         {
  4.             try
  5.             {
  6.                 HttpPostedFileBase postedFile = Request.Files["file"];
  7.                 string serverId = Request.Form.Get("hdnServerId");
  8.                 Business.Domain.Server serverObj = Business.Domain.Server.GetById(Convert.ToInt32(serverId));
  9.                 string logFilesDirectory = serverObj.GetFtpLogFilesDirectory(CasterStats.Core.Win.ApplicationInfo.LogFilesDirectory);
  10.                 if (!Directory.Exists(logFilesDirectory))
  11.                 {
  12.                     Directory.CreateDirectory(logFilesDirectory);
  13.                 }
  14.                 string fileName = Path.GetFileNameWithoutExtension(postedFile.FileName) + "_" + DateTime.Now.ToFileTime() + Path.GetExtension(postedFile.FileName);
  15.                 string filePath = string.Format("{0}\\{1}", logFilesDirectory, fileName);
  16.                 postedFile.SaveAs(filePath);
  17.                 return Content("{success: true, result:\"File uploaded successfully\"}");
  18.             }
  19.             catch (Exception ex)
  20.             {
  21.                 CasterStats.Core.Win.Logging.WareFeedHelper.LogUsageAsync("error", ex.Message);
  22.                 log.Error("File upload failed.", ex);
  23.                 return Content("{success: false, error:\"" + ex.Message + "\"}");
  24.             }
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement