Ejemplo n.º 1
0
        /// <summary>
        ///     This Method is used to return the windows file type icon in rtf form
        /// </summary>
        /// <param name="fileName">
        ///     Out of fileName-extenion the file type icon is extracted
        ///     <br/>
        ///         EXAMPLE:
        ///         fileName = "Hello.doc" ---> Result will be the icon for MS Word document
        /// </param>
        /// <returns>
        ///     A String containing a icon in WMeta8 Icon format (RTF Control string).
        /// </returns>
        public static Image GetFileIcon(string fileName)
        {
            var shinfo = new NativeMethods.ShFileinfo();
            NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo,
                (uint) Marshal.SizeOf(shinfo),
                (uint) (NativeMethods.ShGetFileInfoConstants.ShgfiIcon |
                        NativeMethods.ShGetFileInfoConstants.ShgfiLargeIcon |
                        NativeMethods.ShGetFileInfoConstants.ShgfiUseFileAttributes));

            var fTypeIcon = Icon.FromHandle(shinfo.hIcon);
            return fTypeIcon.ToBitmap();
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     This Method is used to return the windows file type icon in rtf form
        /// </summary>
        /// <param name="fileName">
        ///     Out of fileName-extenion the file type icon is extracted
        ///     <br/>
        ///         EXAMPLE:
        ///         fileName = "Hello.doc" ---> Result will be the icon for MS Word document
        /// </param>
        /// <returns>
        ///     A String containing a icon in WMeta8 Icon format (RTF Control string).
        /// </returns>
        public static Image GetFileIcon(string fileName)
        {
            var shinfo = new NativeMethods.ShFileinfo();

            NativeMethods.SHGetFileInfo(fileName, 0, ref shinfo,
                                        (uint)Marshal.SizeOf(shinfo),
                                        (uint)(NativeMethods.ShGetFileInfoConstants.ShgfiIcon |
                                               NativeMethods.ShGetFileInfoConstants.ShgfiLargeIcon |
                                               NativeMethods.ShGetFileInfoConstants.ShgfiUseFileAttributes));


            var fTypeIcon = Icon.FromHandle(shinfo.hIcon);

            return(fTypeIcon.ToBitmap());
        }