Beispiel #1
0
        /// <summary>
        /// Сopy the directory with the embedded files and directories
        /// </summary>
        /// <param name="sourcePath">Path to the source directory</param>
        /// <param name="destinationPath">Path to the destination directory</param>
        protected virtual void CopyDirectory(string sourcePath, string destinationPath)
        {
            string[] existingFiles       = _fileProvider.GetFiles(sourcePath);
            string[] existingDirectories = _fileProvider.GetDirectories(sourcePath);

            if (!_fileProvider.DirectoryExists(destinationPath))
            {
                _fileProvider.CreateDirectory(destinationPath);
            }

            foreach (string file in existingFiles)
            {
                string filePath = _fileProvider.Combine(destinationPath, _fileProvider.GetFileName(file));
                if (!_fileProvider.FileExists(filePath))
                {
                    _fileProvider.FileCopy(file, filePath);
                }
            }

            foreach (string directory in existingDirectories)
            {
                string directoryPath = _fileProvider.Combine(destinationPath, _fileProvider.GetDirectoryName(directory));
                CopyDirectory(directory, directoryPath);
            }
        }
Beispiel #2
0
        public virtual IActionResult Upload()
        {
            ViewData["resultCode"] = "failed";
            ViewData["result"]     = "No access to this functionality";
            return(View());


            if (Request.Form.Files.Count == 0)
            {
                throw new Exception("No file uploaded");
            }

            var uploadFile = Request.Form.Files.FirstOrDefault();

            if (uploadFile == null)
            {
                ViewData["resultCode"] = "failed";
                ViewData["result"]     = "No file name provided";
                return(View());
            }

            var fileName = _fileProvider.GetFileName(uploadFile.FileName);

            if (string.IsNullOrEmpty(fileName))
            {
                ViewData["resultCode"] = "failed";
                ViewData["result"]     = "No file name provided";
                return(View());
            }

            var directory = "~/wwwroot/images/uploaded/";
            var filePath  = _fileProvider.Combine(_fileProvider.MapPath(directory), fileName);

            var fileExtension = _fileProvider.GetFileExtension(filePath);

            if (!GetAllowedFileTypes().Contains(fileExtension))
            {
                ViewData["resultCode"] = "failed";
                ViewData["result"]     = $"Files with {fileExtension} extension cannot be uploaded";
                return(View());
            }

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                uploadFile.CopyTo(fileStream);
            }

            ViewData["resultCode"] = "success";
            ViewData["result"]     = "success";
            ViewData["filename"]   = Url.Content($"{directory}{fileName}");
            return(View());
        }
Beispiel #3
0
        /// <summary>
        /// Get picture (thumb) local path
        /// </summary>
        /// <param name="thumbFileName">Filename</param>
        /// <returns>Local picture thumb path</returns>
        protected virtual string GetThumbLocalPath(string thumbFileName)
        {
            string thumbsDirectoryPath = _fileProvider.GetAbsolutePath(AgsMediaDefaults.ImageThumbsPath);

            if (_mediaSettings.MultipleThumbDirectories)
            {
                //get the first two letters of the file name
                string fileNameWithoutExtension = _fileProvider.GetFileNameWithoutExtension(thumbFileName);
                if (fileNameWithoutExtension != null && fileNameWithoutExtension.Length > AgsMediaDefaults.MultipleThumbDirectoriesLength)
                {
                    string subDirectoryName = fileNameWithoutExtension.Substring(0, AgsMediaDefaults.MultipleThumbDirectoriesLength);
                    thumbsDirectoryPath = _fileProvider.GetAbsolutePath(AgsMediaDefaults.ImageThumbsPath, subDirectoryName);
                    _fileProvider.CreateDirectory(thumbsDirectoryPath);
                }
            }

            string thumbFilePath = _fileProvider.Combine(thumbsDirectoryPath, thumbFileName);

            return(thumbFilePath);
        }