我试图找出如何读取/写入C#中的扩展文件属性,例如,您可以在Windows资源管理器中看到的注释,比特率,访问日期,类别等.任何想法如何做到这一点?编辑:我主要是读/写视频文件(AVI/DIVX/...)
显然,微软已经(有点)用快速访问项取代了"收藏夹"Windows资源管理器项.但我找不到以编程方式向其添加文件夹的方法(在Google上都不是MSDN).有没有办法做到这一点?
我需要获取在Windows资源管理器中选择的当前文件集合.我从这里找到了以下代码.
不过,我不在那里.首先,它GetForegroundWindow来自哪里?另一方面,编译器在线上抱怨
var shell = new Shell32.Shell();
Run Code Online (Sandbox Code Playgroud)
话
"无法找到类型或命名空间名称'Shell32'(您是否缺少using指令或程序集引用?)".我已经添加了SHDocVw作为参考,但我仍然无法通过编译器.有人可以帮我完成这个吗?
IntPtr handle = GetForegroundWindow();
ArrayList selected = new ArrayList();
var shell = new Shell32.Shell();
foreach(SHDocVw.InternetExplorer window in shell.Windows()) {
if (window.HWND == (int)handle)
{
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
foreach(Shell32.FolderItem item in items)
{
selected.Add(item.Path);
}
}
}
Run Code Online (Sandbox Code Playgroud) 嗯.好的,重新访问PInvoke后,我确信我不太明白: - /(刚问过这个问题)
让我举例说明我需要处理的代码.当我使用"添加引用 - > COM - > Microsoft Shell控件和自动化"时它可以工作......但遗憾的是它在我的项目中放置了一个如下所示的引用:"C:\ Users\Tim\Documents\Visual Studio 2008 \项目\翼\ FileWing\OBJ \调试\ Interop.Shell32.dll"
我正在挖掘回收箱并寻找我想要恢复的物品.有没有办法不通过PInvoke来完成这项工作?或者获取对system32/shell32.dll的引用,它允许我在运行时使用此代码?
private void recoverRecyclerBinEntry(string fileName, int size)
{
try
{
Shell Shl = new Shell();
Folder Recycler = Shl.NameSpace(10);
// scans through all the recyclers entries till the one to recover has been found
for (int i = 0; i < Recycler.Items().Count; i++)
{
FolderItem FI = Recycler.Items().Item(i);
string FileName = Recycler.GetDetailsOf(FI, 0);
if (Path.GetExtension(FileName) == "")
FileName += Path.GetExtension(FI.Path); …Run Code Online (Sandbox Code Playgroud) 有没有办法打开Windows快捷方式(.lnk文件)并更改它的目标?我找到了以下代码片段,它允许我找到当前目标,但它是一个只读属性:
Shell32::Shell^ shl = gcnew Shell32::Shell();
String^ shortcutPos = "C:\\some\\path\\to\\my\\link.lnk";
String^ lnkPath = System::IO::Path::GetFullPath(shortcutPos);
Shell32::Folder^ dir = shl->NameSpace(System::IO::Path::GetDirectoryName(lnkPath));
Shell32::FolderItem^ itm = dir->Items()->Item(System::IO::Path::GetFileName(lnkPath));
Shell32::ShellLinkObject^ lnk = (Shell32::ShellLinkObject^)itm->GetLink;
String^ target = lnk->Target->Path;
Run Code Online (Sandbox Code Playgroud)
我找不到任何改变目标的东西.我唯一的选择是创建一个新的快捷方式来覆盖当前的快捷方式吗?..如果是的话,我该怎么做?
我正在使用 IWshRuntimeLibrary 用 C# 创建快捷方式。快捷方式文件名是印地语“??????”。
我正在使用以下代码我的片段来创建快捷方式,其中 shortcutName = "??????.lnk"
WshShellClass wshShell = new WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut;
shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(destPath + "\\" + shortcutName);
shortcut.TargetPath = sourcePath;
shortcut.Save();
Run Code Online (Sandbox Code Playgroud)
在shortcut.Save()我得到以下异常。
The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)
Run Code Online (Sandbox Code Playgroud)