コード例 #1
0
        /// <summary>
        /// Get the file type in words.  For example, a .pdf file would be Acrobat Document
        /// </summary>
        /// <param name="extension">The file extension</param>
        /// <returns>The type of the file in words</returns>
        public static string GetFileTypeInWords(string extension)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Requested file type in words for extension " + extension);
            }

            // We need to get this from the file types
            Hashtable theTypesHash = FileTypesBLL.GetFileTypesExtensionHash();

            if (!theTypesHash.Contains(extension.ToUpper()))
            {
                log.Error("Failed to find the extension " + extension + " in the file type list");
                return(Resources.Files.UnknownFileType);
            }

            FileType theFileType = (FileType)theTypesHash[extension.ToUpper()];

            if (log.IsDebugEnabled)
            {
                log.Debug("Found description \"" + theFileType.Description +
                          "\" for extension " + extension);
            }

            return(theFileType.Description);
        }
コード例 #2
0
        /// <summary>
        /// Get the name of the provider that is in charge of extracting the text for the file type
        /// </summary>
        /// <param name="extension">The file extension</param>
        /// <returns>The name of the provider that should be used or null if one does not exist</returns>
        public static string GetFileTextExtractionProvider(string extension)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Requested text extraction provider for extension " + extension);
            }

            // We need to get this from the file types
            Hashtable theTypesHash = FileTypesBLL.GetFileTypesExtensionHash();

            if (!theTypesHash.Contains(extension.ToUpper()))
            {
                log.Error("Failed to find the extension " + extension + " in the file type list");
                return(null);
            }

            FileType theFileType = (FileType)theTypesHash[extension.ToUpper()];

            if (log.IsDebugEnabled)
            {
                log.Debug("Found text extraction provider \"" + theFileType.Provider +
                          "\" for extension " + extension);
            }

            return(theFileType.Provider);
        }
コード例 #3
0
        /// <summary>
        /// Determines if an image file should be allowed to be uploaded to the system
        /// </summary>
        /// <param name="fileName">The image file name to verify</param>
        /// <returns>True if the file should be allowed, false otherwise</returns>
        public static bool IsAnImageFile(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                log.Warn("Called IsAnImageFile with null or empty filename");
                return(false);
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Trying to determine if file " + fileName + " is an Image valid file");
            }

            FileInfo theFileInfo = new FileInfo(fileName);
            string   extension   = theFileInfo.Extension;

            // We need to get this from the file types
            Hashtable theTypesHash = FileTypesBLL.GetFileTypesExtensionHash();

            if (!theTypesHash.Contains(extension.ToUpper()))
            {
                log.Error("Failed to find the extension " + extension + " in the file type list");
                return(false);
            }

            FileType theFileType = (FileType)theTypesHash[extension.ToUpper()];

            if (theFileType.Image)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        /// <summary>
        /// Get the location of the medium icon for this file type
        /// </summary>
        /// <param name="extension">The file extension</param>
        /// <param name="iconsize">The size of the required icon</param>
        /// <returns>The location of the icon that should  be used</returns>
        public static string GetFileIconURL(string extension, IconSize iconsize, IconType icontype)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug("Requested " + iconsize.ToString() + "icon for extension " + extension);
            }

            // We need to get this from the file types
            Hashtable theTypesHash = FileTypesBLL.GetFileTypesExtensionHash();

            if (!theTypesHash.Contains(extension.ToUpper()))
            {
                log.Error("Failed to find the extension " + extension + " in the file type list");
                return(Resources.Files.FileIconDirectory + "/" + Resources.Files.UnknownFileIcon);
            }

            FileType theFileType = (FileType)theTypesHash[extension.ToUpper()];
            string   iconPath    = "";

            if (icontype == IconType.StandardIcon)
            {
                if (iconsize == IconSize.SmallIcon)
                {
                    iconPath = Resources.Files.FileIconDirectory + "/" + theFileType.SmallIcon;
                }
                else if (iconsize == IconSize.MediumIcon)
                {
                    iconPath = Resources.Files.FileIconDirectory + "/" + theFileType.MediumIcon;
                }
                else if (iconsize == IconSize.LargeIcon)
                {
                    iconPath = Resources.Files.FileIconDirectory + "/" + theFileType.LargeIcon;
                }
                else
                {
                    throw new ArgumentException("invalid icon size " + iconsize.ToString());
                }
            }
            else
            {
                if (iconsize == IconSize.SmallIcon)
                {
                    iconPath = Resources.Files.FileIconDirectory + "/" + theFileType.SmallCustomIcon;
                }
                else if (iconsize == IconSize.MediumIcon)
                {
                    iconPath = Resources.Files.FileIconDirectory + "/" + theFileType.MediumCustomIcon;
                }
                else if (iconsize == IconSize.LargeIcon)
                {
                    iconPath = Resources.Files.FileIconDirectory + "/" + theFileType.LargeCustomIcon;
                }
                else
                {
                    throw new ArgumentException("invalid icon size " + iconsize.ToString());
                }
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Found icon \"" + iconPath + "\" for size " + iconsize.ToString() +
                          "for extension " + extension);
            }

            return(iconPath);
        }