public HttpResponseMessage ImagesLookupExt(string q, string folder)
        {
            try
            {
                var    folderManager = FolderManager.Instance;
                string imageFolder   = "OpenContent/Files/" + ActiveModule.ModuleID;

                if (!string.IsNullOrEmpty(folder))
                {
                    imageFolder = folder;
                }
                var dnnFolder = folderManager.GetFolder(PortalSettings.PortalId, imageFolder);
                if (dnnFolder == null)
                {
                    dnnFolder = folderManager.AddFolder(PortalSettings.PortalId, imageFolder);
                }

                var files = folderManager.GetFiles(dnnFolder, true);
                files = files.Where(f => IsImageFile(f));
                if (q != "*" && !string.IsNullOrEmpty(q))
                {
                    files = files.Where(f => f.FileName.ToLower().Contains(q.ToLower()));
                }
                int folderLength = imageFolder.Length;
                var res          = files.Select(f => new
                {
                    id       = f.FileId.ToString(),
                    thumbUrl = ImageHelper.GetImageUrl(f, new Ratio(40, 40)),  //todo for install in application folder is dat niet voldoende ???
                    url      = DnnFileUtils.RemoveCachbuster(FileManager.Instance.GetUrl(f)),
                    text     = f.Folder.Substring(folderLength).TrimStart('/') + f.FileName
                }).Take(1000);

                return(Request.CreateResponse(HttpStatusCode.OK, res));
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
Beispiel #2
0
        // Upload entire file
        private void UploadWholeFile(HttpContextBase context, ICollection <FilesStatus> statuses)
        {
            for (var i = 0; i < context.Request.Files.Count; i++)
            {
                var file = context.Request.Files[i];
                if (file == null)
                {
                    continue;
                }

                var fileName = CleanUpFileName(Path.GetFileName(file.FileName));


                if (IsAllowedExtension(fileName))
                {
                    string uploadfolder = "OpenContent/Files/" + ActiveModule.ModuleID;

                    if (!string.IsNullOrEmpty(context.Request.Form["uploadfolder"]))
                    {
                        uploadfolder = context.Request.Form["uploadfolder"];
                    }
                    var userFolder = _folderManager.GetFolder(PortalSettings.PortalId, uploadfolder);
                    if (userFolder == null)
                    {
                        userFolder = _folderManager.AddFolder(PortalSettings.PortalId, uploadfolder);
                    }
                    int    suffix       = 0;
                    string baseFileName = Path.GetFileNameWithoutExtension(fileName);
                    string extension    = Path.GetExtension(fileName);
                    var    fileInfo     = _fileManager.GetFile(userFolder, fileName);
                    while (fileInfo != null)
                    {
                        suffix++;
                        fileName = baseFileName + "-" + suffix + extension;
                        fileInfo = _fileManager.GetFile(userFolder, fileName);
                    }
                    fileInfo = _fileManager.AddFile(userFolder, fileName, file.InputStream, true);
                    var fileIcon = IconController.IconURL("Ext" + fileInfo.Extension, "32x32");
                    if (!File.Exists(context.Server.MapPath(fileIcon)))
                    {
                        fileIcon = IconController.IconURL("File", "32x32");
                    }
                    statuses.Add(new FilesStatus
                    {
                        success       = true,
                        name          = fileName,
                        extension     = fileInfo.Extension,
                        type          = fileInfo.ContentType,
                        size          = file.ContentLength,
                        progress      = "1.0",
                        url           = DnnFileUtils.RemoveCachbuster(fileInfo.ToUrl()),
                        thumbnail_url = fileIcon,
                        message       = "success",
                        id            = fileInfo.FileId,
                    });
                }
                else
                {
                    statuses.Add(new FilesStatus
                    {
                        success = false,
                        name    = fileName,
                        message = "File type not allowed."
                    });
                }
            }
        }