如何获取文件类型文本 [英] How can I get File Type Text
本文介绍了如何获取文件类型文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果打开包含PDF文件的文件夹,并将视图设置为详细信息视图,则会在类型"列中找到所使用的"Adobe Acrobat文件".
如何通过编程找到此文本.像这里一样:
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");
文本为"Adobe Acrobat文件";
and text be ''Adobe Acrobat File'';
推荐答案
尝试以下操作:
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);
}
}
}
这篇关于如何获取文件类型文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文