Exemplo n.º 1
0
        public ActionResult CreateImageFolder(string folderName)
        {
            string path = Path.Combine(Server.MapPath("~" + _rootImagesFolderPath), folderName);
            var viewModel = new CombinedHTMLImageUpload();
            viewModel = UpdateFolders(viewModel, null);
            try
            {
                // Determine whether the directory exists.
                if (Directory.Exists(path))
                {
                    viewModel.Message = string.Format("The directory{0} exists already.", folderName);
                    Console.WriteLine(viewModel.Message);
                    return PartialView("ImageUpload", viewModel);
                }

                // Try to create the directory.
                DirectoryInfo di = Directory.CreateDirectory(path);
                viewModel.Message = string.Format("The directory{0} was created successfully at {1}.", folderName, Directory.GetCreationTime(path));
                Console.WriteLine(viewModel.Message);

            }
            catch (Exception e)
            {
                viewModel.Message = string.Format("The process failed: {0}", e.ToString());
                Console.WriteLine(viewModel.Message);
                return PartialView("ImageUpload", viewModel);
            }

            viewModel = UpdateFolders(viewModel, folderName);

            return PartialView("ImageUpload", viewModel);
        }
Exemplo n.º 2
0
        public ActionResult ImageUpload(string selectedFolderUrl, HttpPostedFileBase fileUpload)
        {
            var fileUploaded = (fileUpload != null && fileUpload.ContentLength > 0) ? true : false;
            var viewModel = new CombinedHTMLImageUpload();
            viewModel = UpdateFolders(viewModel, null);

            try
            {
                if (string.IsNullOrEmpty(selectedFolderUrl))
                {
                    viewModel.Message = string.Format("Selected directory{0} not valid.", selectedFolderUrl);
                    Console.WriteLine(viewModel.Message);
                    return PartialView("ImageUpload", viewModel);
                }
                // Determine whether the directory exists.
                if (!Directory.Exists(selectedFolderUrl))
                {
                    viewModel.Message = string.Format("Selected directory{0} does not exists.", selectedFolderUrl);
                    Console.WriteLine(viewModel.Message);
                    return PartialView("ImageUpload", viewModel);
                }

                if (!fileUploaded)
                {
                    viewModel.Message = string.Format("Upload failed.");
                    Console.WriteLine(viewModel.Message);
                    return PartialView("ImageUpload", viewModel);
                }

                string fileName = Path.GetFileName(fileUpload.FileName);

                // Try to save image.
                fileUpload.SaveAs(Path.Combine(selectedFolderUrl, fileName));
                viewModel = UpdateFolders(viewModel, new DirectoryInfo(selectedFolderUrl).Name);
                viewModel.Message = string.Format("Image {0} was succecfully uploaded.", fileName);
            }
            catch (Exception e)
            {
                viewModel.Message = string.Format("The process failed: {0}", e.ToString());
                Console.WriteLine(viewModel.Message);
                return PartialView("ImageUpload", viewModel);
            }

            return PartialView(viewModel);
        }
Exemplo n.º 3
0
        private CombinedHTMLImageUpload UpdateFolders(CombinedHTMLImageUpload viewModel, string selected)
        {
            viewModel.Folders = GetImageFoldrs();
            if (!string.IsNullOrEmpty(selected))
            {
                viewModel.SelectedFolder = viewModel.Folders.Where(x => x.Name == selected).Last();
            }
            else
            {
                viewModel.SelectedFolder = viewModel.Folders.Where(x => x.Name == _rootImagesFolder).Last();
            }

            return viewModel;
        }
Exemplo n.º 4
0
        public ActionResult ImageUpload(HttpPostedFileBase fileUpload)
        {
            var fileUploaded = (fileUpload != null && fileUpload.ContentLength > 0) ? true : false;
            var viewModel = new CombinedHTMLImageUpload();

            try
            {

                if (!fileUploaded)
                {
                    viewModel.Message = string.Format("Не вдалось завантажити зображення.");
                    Console.WriteLine(viewModel.Message);
                    return PartialView("ImageUpload", viewModel);
                }

                string fileName = Path.GetFileName(fileUpload.FileName);
                string saveLocation = Path.Combine(Server.MapPath(_rootImagesFolderPath), fileName);
                // Try to save image.
                fileUpload.SaveAs(saveLocation);
                viewModel.ImageUploaded = "<IMG id='ImageUploaded' src=" + Path.Combine(_rootImagesFolderPath, fileName) + " style='float: left;'/>";
                viewModel.Message = string.Format("Зображення {0} було успішно завантажено.", fileName);
            }
            catch (Exception e)
            {
                // viewModel.Message = string.Format("The process failed: {0}", e.ToString());
                Console.WriteLine(viewModel.Message);
                return PartialView("ImageUpload", viewModel);
            }

            return PartialView(viewModel);
        }