Click here to Skip to main content
15,910,797 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
if you open a folder which have PDF file , and you set view to details view , you will find out that in Type column , 'Adobe Acrobat File' used .

how can I find this text with programming . like here :

string text = GetTypeText(@"D:\hello.pdf");


and text be 'Adobe Acrobat File';
Posted

1 solution

Try this:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace GUITester
    {
    public partial class Form1 : Form
        {
        [StructLayout(LayoutKind.Sequential)]
        public struct SHFILEINFO
            {
            public IntPtr hIcon;
            public IntPtr iIcon;
            public uint dwAttributes;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
            public string szDisplayName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
            public string szTypeName;
            };

        class Win32
            {
            public const uint SHGFI_DISPLAYNAME = 0x00000200;
            public const uint SHGFI_TYPENAME = 0x400;
            public const uint SHGFI_ICON = 0x100;
            public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
            public const uint SHGFI_SMALLICON = 0x1; // 'Small icon

            [DllImport("shell32.dll")]
            public static extern IntPtr SHGetFileInfo(string pszPath, uint
            dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
            }
        public Form1()
            {
            InitializeComponent();
            SHFILEINFO shinfo = new SHFILEINFO();
            IntPtr i = Win32.SHGetFileInfo(@"F:\Temp\YYY.pdf", 0, ref shinfo, (uint) Marshal.SizeOf(shinfo), Win32.SHGFI_TYPENAME);
            string s = Convert.ToString(shinfo.szTypeName.Trim());
            MessageBox.Show(s);
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900