Esempio n. 1
0
		/// <summary>
		/// Gets the document type of a file.
		/// </summary>
		/// <param name="fullpath">Full path to file.</param>
		/// <returns>Document type of file.</returns>
		public static String GetFileType(String fullpath)
		{
			int retval = 0;
			var info = new Win32API.Shell32.SHFILEINFO(true);

			retval = Win32API.Shell32.SHGetFileInfo(fullpath, 0, ref info, Marshal.SizeOf(info), Win32API.Shell32.SHGFI_TYPENAME);
			if (retval == 0)
				return "Unknown";		// Error occured
			else
				return info.szTypeName;			
		}
Esempio n. 2
0
		/// <summary>
		/// Gets the icon associated with a given file.
		/// </summary>
		/// <param name="fullpath">Path to file.</param>
		/// <param name="iconSize">Size of icon to return.</param>
		/// <returns>Icon associated with the given file.</returns>
		public static Icon GetFileIcon(String fullpath, FileIconSize iconSize) 
		{
			var retval = 0;
			var info = new Win32API.Shell32.SHFILEINFO();
			uint flags = Win32API.Shell32.SHGFI_USEFILEATTRIBUTES | Win32API.Shell32.SHGFI_ICON;

			if (iconSize == FileIconSize.Small)
			{
				flags |= Win32API.Shell32.SHGFI_SMALLICON;
			} 
			else if (iconSize == FileIconSize.Large)
			{
				flags |= Win32API.Shell32.SHGFI_LARGEICON;
			}

			retval = Win32API.Shell32.SHGetFileInfo(fullpath, Win32API.Shell32.FILE_ATTRIBUTE_NORMAL, ref info, Marshal.SizeOf(info), flags);
			if (retval == 0) return null;

			return Icon.FromHandle(info.hIcon);
		}