首先必须添加Shell32:程序中需要引用shell32.dll,我的具体步骤如下:在“引用”上右键选“添加引用”,在弹出的对话框中选“COM”选项卡,找到组件“Microsoft Shell Controls AndAutomation 1.0”
using System.IO;
using Shell32;
OpenFileDialog ofd = new OpenFileDialog(); //new一个方法
ofd.Filter = "MP3 Files(.mp3)|*.mp3|WMA Files(*.wma)|*.WMA|ALL Files(*.*)|*.*";
ofd.Multiselect = true; //允许多选
ofd.RestoreDirectory = true; //记住上一次的文件路径
ofd.ShowDialog(); //显示打开文件的窗口
filePath = ofd.FileName; //获取文件的完整的路径
FileInfo fInfo = new FileInfo(filePath);
ShellClass sh = new ShellClass();
Folder dir = sh.NameSpace(Path.GetDirectoryName(filePath));
FolderItem item = dir.ParseName(Path.GetFileName(filePath));
StringBuilder sb = new StringBuilder();
for (int i = -1; i < 50;i++ )
{
sb.Append(i.ToString()) ;
sb.Append(":");
sb.Append(dir.GetDetailsOf(item,i));
sb.Append("\r\n");
}
string str = sb.ToString();
输出的结果:
-1:项目类型: MP3 格式声音
大小: 5.42 MB
参与创作的艺术家: 张敬轩
长度: 00:03:51
0:吻得太逼真
1:5.42 MB
2:MP3 格式声音
3:2010/7/30 17:03
4:2011/8/3 0:35
5:2010/7/30 17:03
6:A
7:
8:
9:音频
10:ZJD-PC\ZJD
11:音乐
12:
13:张敬轩
14:Urban Emotions
15:2008
16:华语流行音乐【Chinese Pop Music】
17:
18:
19:未分级
20:张敬轩
21:吻得太逼真
22:
23:
24:
25:
26:14
27:00:03:51
28:?196kbps
29:否
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49: