Beispiel #1
0
        protected void ProcessFileUploads(ProductBundleEditAdminViewModel viewModel, StoreFront storeFront)
        {
            string virtualFolder = storeFront.CatalogProductBundleContentVirtualDirectoryToMap(Request.ApplicationPath);
            string fileFolder    = Server.MapPath(virtualFolder);

            if (!System.IO.Directory.Exists(fileFolder))
            {
                System.IO.Directory.CreateDirectory(fileFolder);
            }

            HttpPostedFileBase imageFile = Request.Files["ImageName_File"];

            if (imageFile != null && imageFile.ContentLength != 0)
            {
                string newFileName = imageFile.FileNameNoPath();
                if (!string.IsNullOrEmpty(Request.Form["ImageName_ChangeFileName"]))
                {
                    newFileName = viewModel.UrlName + "_Image." + imageFile.FileName.FileExtension();
                }

                try
                {
                    imageFile.SaveAs(fileFolder + "\\" + newFileName);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Error saving bundle image file '" + imageFile.FileName + "' as '" + newFileName + "'", ex);
                }

                viewModel.ImageName = newFileName;
                AddUserMessage("Image Uploaded!", "Bundle Image '" + imageFile.FileName.ToHtml() + "' " + imageFile.ContentLength.ToByteString() + " was saved as '" + newFileName + "'", UserMessageType.Success);
            }
        }
        protected void ProcessFileUploads(ProductBundleEditAdminViewModel viewModel, StoreFront storeFront)
        {
            string virtualFolder = storeFront.CatalogProductBundleContentVirtualDirectoryToMap(Request.ApplicationPath);
            string fileFolder = Server.MapPath(virtualFolder);
            if (!System.IO.Directory.Exists(fileFolder))
            {
                System.IO.Directory.CreateDirectory(fileFolder);
            }

            HttpPostedFileBase imageFile = Request.Files["ImageName_File"];
            if (imageFile != null && imageFile.ContentLength != 0)
            {
                string newFileName = imageFile.FileNameNoPath();
                if (!string.IsNullOrEmpty(Request.Form["ImageName_ChangeFileName"]))
                {
                    newFileName = viewModel.UrlName + "_Image." + imageFile.FileName.FileExtension();
                }

                try
                {
                    imageFile.SaveAs(fileFolder + "\\" + newFileName);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Error saving bundle image file '" + imageFile.FileName + "' as '" + newFileName + "'", ex);
                }

                viewModel.ImageName = newFileName;
                AddUserMessage("Image Uploaded!", "Bundle Image '" + imageFile.FileName.ToHtml() + "' " + imageFile.ContentLength.ToByteString() + " was saved as '" + newFileName + "'", UserMessageType.Success);
            }
        }
Beispiel #3
0
        public static IEnumerable <SelectListItem> ProductBundleFileListForModel(this HtmlHelper htmlHelper, string searchPattern = "*.*", bool filterForImages = false, bool filterForAudio = false)
        {
            string selectedFileName = (htmlHelper.ViewData.Model as string ?? "").ToLower();

            StoreFront storeFront = htmlHelper.CurrentStoreFront(true);
            Client     client     = storeFront.Client;

            HttpContextBase http = htmlHelper.ViewContext.RequestContext.HttpContext;

            string storeFrontVirtualPath = storeFront.CatalogProductBundleContentVirtualDirectoryToMap(http.Request.ApplicationPath);
            string storeFrontFolderPath  = http.Server.MapPath(storeFrontVirtualPath);
            List <SelectListItem> storeFrontListItems = new List <SelectListItem>();

            if (System.IO.Directory.Exists(storeFrontFolderPath))
            {
                DirectoryInfo   storeFrontFolder = new System.IO.DirectoryInfo(storeFrontFolderPath);
                List <FileInfo> storeFrontFiles  = storeFrontFolder.GetFiles(searchPattern).ToList();
                if (filterForImages && filterForAudio)
                {
                    storeFrontFiles = storeFrontFiles.Where(f => f.Name.FileExtensionIsImage() || f.Name.FileExtensionIsAudio()).ToList();
                }
                else if (filterForImages)
                {
                    storeFrontFiles = storeFrontFiles.Where(f => f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForAudio)
                {
                    storeFrontFiles = storeFrontFiles.Where(f => f.Name.FileExtensionIsAudio()).ToList();
                }

                SelectListGroup storeFrontGroup = new SelectListGroup()
                {
                    Name = "Store Front"
                };
                storeFrontListItems = storeFrontFiles.Select(fil =>
                                                             new SelectListItem()
                {
                    Value    = fil.Name,
                    Text     = fil.Name + (fil.Name.ToLower() == selectedFileName ? " [SELECTED]" : "") + " " + fil.Length.ToByteString(),
                    Selected = fil.Name.ToLower() == selectedFileName,
                    Group    = storeFrontGroup
                }).ToList();
            }

            string clientVirtualPath = client.CatalogProductBundleContentVirtualDirectoryToMap(http.Request.ApplicationPath);
            string clientFolderPath  = http.Server.MapPath(clientVirtualPath);
            List <SelectListItem> clientListItems = new List <SelectListItem>();

            if (System.IO.Directory.Exists(clientFolderPath))
            {
                DirectoryInfo   clientFolder = new System.IO.DirectoryInfo(clientFolderPath);
                List <FileInfo> clientFiles  = clientFolder.EnumerateFiles(searchPattern).ToList();
                if (filterForAudio && filterForImages)
                {
                    clientFiles = clientFiles.Where(f => f.Name.FileExtensionIsAudio() || f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForImages)
                {
                    clientFiles = clientFiles.Where(f => f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForAudio)
                {
                    clientFiles = clientFiles.Where(f => f.Name.FileExtensionIsAudio()).ToList();
                }

                SelectListGroup clientGroup = new SelectListGroup()
                {
                    Name = "Client"
                };
                clientListItems = clientFiles.Select(fil =>
                                                     new SelectListItem()
                {
                    Value    = fil.Name,
                    Text     = fil.Name + (fil.Name.ToLower() == selectedFileName ? " [SELECTED]" : "") + " " + fil.Length.ToByteString(),
                    Selected = fil.Name.ToLower() == selectedFileName,
                    Group    = clientGroup
                }).ToList();
            }

            string serverVirtualPath = "~/Content/Server/CatalogContent/Bundles";
            string serverFolderPath  = http.Server.MapPath(serverVirtualPath);
            List <SelectListItem> serverListItems = new List <SelectListItem>();

            if (System.IO.Directory.Exists(serverFolderPath))
            {
                DirectoryInfo   serverFolder = new System.IO.DirectoryInfo(serverFolderPath);
                List <FileInfo> serverFiles  = serverFolder.EnumerateFiles(searchPattern).ToList();
                if (filterForAudio && filterForImages)
                {
                    serverFiles = serverFiles.Where(f => f.Name.FileExtensionIsAudio() || f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForImages)
                {
                    serverFiles = serverFiles.Where(f => f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForAudio)
                {
                    serverFiles = serverFiles.Where(f => f.Name.FileExtensionIsAudio()).ToList();
                }

                SelectListGroup serverGroup = new SelectListGroup()
                {
                    Name = "GStore Files"
                };
                serverListItems = serverFiles.Select(fil =>
                                                     new SelectListItem()
                {
                    Value    = fil.Name,
                    Text     = fil.Name + (fil.Name.ToLower() == selectedFileName ? " [SELECTED]" : "") + " " + fil.Length.ToByteString(),
                    Selected = fil.Name.ToLower() == selectedFileName,
                    Group    = serverGroup
                }).ToList();
            }

            return(storeFrontListItems.Concat(clientListItems).Concat(serverListItems));
        }