我需要获取在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) 好.我已经阅读了几十篇关于你不能从服务器端ASP页面使用MessageBox.Show的文章.说得通.这些文章主张使用"警告"来弹出消息(如确认消息,用户必须单击"确定"以确认消息).一些帖子谈到了注册代码,但其他人没有.我已经尝试了所有可以找到的组合,但是仍然无法让我的服务器端ASP页面在我的客户端浏览器中弹出消息!
这是我的代码隐藏页面中的代码片段:
private void MessageBoxShow(Page page, string message)
{
Literal ltr = new Literal();
ltr.Text = @"<script type='text/javascript'> alert('" + message + "') </script>";
page.Controls.Add(ltr);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过这种变化:
protected void MyTrace(string msg)
{
Response.Write("<script>alert('" + msg + "')</script>");
}
Run Code Online (Sandbox Code Playgroud)
如果我要访问localhost,这两个工作都按预期工作,但是当我将代码放在服务器上时(在IIS 7.5下),消息永远不会出现.
有人可以给我一个简单(但完整)的答案吗?谢谢.
我有一个测试程序,它应该遍历C:下的所有文件.当它到达"Documents and Settings"文件夹时它会死掉.我想忽略错误并继续循环其余文件.问题是,抛出异常在的foreach,所以把一个try/catch绕foreach会导致循环退出.并把一try/catch后foreach永远不会触发(因为抛出异常的的foreach).有没有办法忽略异常并继续处理循环?
这是代码:
static void Main(string[] args)
{
IEnumerable<string> files = Directory.EnumerateFiles(@"C:\", "*.*",
SearchOption.AllDirectories);
foreach (string file in files) // Exception occurs when evaluating "file"
Console.WriteLine(file);
}
Run Code Online (Sandbox Code Playgroud)