Example #1
0
 protected void DeleteUploadedFile(string contentPath)
 {
     try
     {
         string fullPath = GanzUtils.ProperPathCombine('\\', this.WebHost.WebRootPath, contentPath);
         if (File.Exists(fullPath))
         {
             File.Delete(fullPath);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
        public async Task <IActionResult> UploadFiles(IFormFile[] files, string currentDirectory)
        {
            try
            {
                string result = "";

                if (HttpContext.Request.Form.Files.Any())
                {
                    foreach (var file in HttpContext.Request.Form.Files)
                    {
                        string requestedPath = "\\";

                        if (currentDirectory != null)
                        {
                        }

                        string filename = DateTime.Now.ToString("yyMMdd_HHmm") + "_" + file.FileName;
                        string path     = GanzUtils.ProperPathCombine('\\', environment.WebRootPath, "content\\uploads", requestedPath, filename);

                        using (FileStream stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }

                        result = $"{{ \"success\" : 1, \"file\": {{ \"url\" : \"./content/uploads/{requestedPath}/{filename}\" }} }}";
                    }

                    return(this.StatusCode(200, result));
                }
                else
                {
                }

                return(this.StatusCode(404));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(500, ex.Message));
            }
        }