我只是好奇:
List<string> ADUsers = new List<string>();
using (PrincipalContext principle_context = new PrincipalContext(ContextType.Domain, "MYDOMAIN"))
using (UserPrincipal user_principal = new UserPrincipal(principle_context) { Enabled = true, Name = "*", EmailAddress = "*" })
using (PrincipalSearcher user_searcher = new PrincipalSearcher(user_principal))
using (PrincipalSearchResult<Principal> results = user_searcher.FindAll())
{
foreach (Principal p in results)
{
ADUsers.Add(p.Name + " " + ((UserPrincipal)p).EmailAddress);
}
}
Run Code Online (Sandbox Code Playgroud)
...有没有办法避免在这里投射我的结果?我想做的事情如下:
using (PrincipalSearchResult<UserPrincipal> results = user_searcher.FindAll())
Run Code Online (Sandbox Code Playgroud)
...所以我的搜索结果将是我需要它的类型,但似乎FindAll方法只允许使用该<Principal>类型.有没有更好的办法?
谢谢.
在使用不显眼验证的ASP MVC项目中,是否有一种方法可以动态地从元素中删除Required属性?
元素在视图模型中使用Required注释进行修饰.我想我可以通过使用JQuery删除html属性"data-val-required"来删除它,但客户端验证仍然会根据需要处理该元素.是否无法通过操纵不显眼的验证属性来操纵元素的验证?
这是我尝试过的,但它没有用.如果未选中复选框,我想删除所需的属性.
$("#chkTempHire").click(function () {
var checked = $(this).attr("checked");
var attr = $("#txtTempHireEndDate").attr("data-val-required");
var hasAttr = false;
if (typeof attr !== typeof undefined && attr !== false)
hasAttr = true;
if (!checked && hasAttr)
$("#txtTempHireEndDate").removeAttr("data-val-required");
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么,还是不可能?
谢谢!
我对JQuery验证插件行为有点困惑.
如果我有以下JQuery:
$('#form1').validate({
/* other validation */
});
$('#txt1').rules("add",
{
required: true,
messages: { required: 'This is required!' }
});
Run Code Online (Sandbox Code Playgroud)
和以下文本输入,具有id但没有name属性:
<input type="text" id="txt1"/>
Run Code Online (Sandbox Code Playgroud)
文本框中不会弹出所需的消息.
但是,如果我添加名称属性:
<input type="text" id="txt1" name="anything"/>
Run Code Online (Sandbox Code Playgroud)
它验证它很好.
这是为什么?由于我在ID选择器上使用规则("添加",规则)方法,为什么它需要name属性才能将规则与元素相关联?感谢您的任何见解!
我的公司正在使用一个不幸的第三方产品,该产品要求用户保持登录到运行其产品的两个实例的 XP 工作站。
我试图 在 Windows 服务中使用它来获取每个打开的窗口的标题以进行监控,但它们总是返回 null 或空。但是,我可以获得进程名称,就好了。我对标题而不是进程名称感兴趣的原因是进程名称相同(同一应用程序的两个实例)但标题是唯一的。对于任何打开的窗口,我也得到相同的结果,例如记事本的打开实例。
该服务正在作为运行第三方应用程序的两个实例的用户运行。
所以我很好奇,为什么我可以得到进程名称,而不是标题?是否需要SERVICE_INTERACTIVE_PROCESS出于某种原因指定查看标题,而不是名称?(当然我不会使用那个标志:http : //blogs.msdn.com/b/larryosterman/archive/2005/09/14/466175.aspx)
我的代码:
static void check_Clients()
{
Process[] processList = Process.GetProcesses();
TextWriter t = new StreamWriter(@"C:\temp\svctesting.txt", true);
foreach (Process process in processList)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
// I never get to this point, titles are always null or empty
t.WriteLine("Process Title: " + process.MainWindowTitle);
}
else
{
// this works fine
t.WriteLine("Process Name: " + process.ProcessName);
}
}
t.Close();
t = null;
} …Run Code Online (Sandbox Code Playgroud) 我在使用 Shell32 CopyHere 方法时遇到了一些问题。
首先,我从这个页面工作:http : //www.codeproject.com/Tips/257193/Easily-zip-unzip-files-using-Windows-Shell32
我希望用 C# 重写类似的东西,因为我几乎没有在 VB.NET 中工作过。
我正在传递一个输入目录,其中有一个文本文件作为我的测试。在底部,只是为了让我看到它实际上是在抓取我的文件,我写了 input.Items() 的计数,我得到了 1,所以我认为它看到的是我的目录,其中包含一个文本文件。但是,虽然我的代码创建了空的 zip 文件就好了,并且至少从控制台输出似乎正在抓取我的文件,但它实际上并没有将任何内容复制到 zip 文件中。不会抛出任何错误,就好像什么都没发生一样。
static void Zip(string i, string o)
{
//Turn relative paths into full paths for Shell.NameSpace method.
string ifp = Path.GetFullPath(i);
string ofp = Path.GetFullPath(o);
//Validate parameters.
if (!(Directory.Exists(ifp)) || (Directory.GetFiles(ifp).Count() <= 0))
throw new Exception("Input directory " + i + " was invalid. " + i + " was either empty or doesn't exist.");
string ext = ofp.Substring(ofp.Length - …Run Code Online (Sandbox Code Playgroud) c# ×3
jquery ×2
asp.net-mvc ×1
javascript ×1
process ×1
service ×1
shell32 ×1
shell32.dll ×1
windows ×1
zip ×1