我有一个带有App.config的WinForms .exe,它有一堆在运行时设置并保存的User Scoped Settings.我希望能够使用WinForms应用程序更改和保存设置,然后单击按钮根据这些设置执行一些工作.我还想从sep中读取同一.config文件中的用户设置.控制台应用程序,所以我可以安排工作作为计划任务完成.能够做到这一点的最佳方法是什么?
更新:我尝试了使用ConfigurationManager.OpenExeConfiguration的建议,如某些答案中所述.
Configuration config = ConfigurationManager.OpenExeConfiguration("F:\\Dir\\App.exe");
Run Code Online (Sandbox Code Playgroud)
但是当我尝试检索这样的用户设置时.
string result = config.AppSettings.Settings["DB"].ToString();
Run Code Online (Sandbox Code Playgroud)
我得到一个Null引用错误.
从exe中的代码,但以下正确返回数据库名称.
Properties.Settings.Default.DB
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
更新2:
所以基于下面的一些答案,我现在可以使用以下内容从sep中检索我感兴趣的user.config文件部分的原始XML.ConsoleApp.
System.Configuration.ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"D:\PathHere\user.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);
System.Configuration.DefaultSection configSection = (System.Configuration.DefaultSection)config.GetSection("userSettings");
string result = configSection.SectionInformation.GetRawXml();
Console.WriteLine(result);
Run Code Online (Sandbox Code Playgroud)
但我仍然无法为我感兴趣的特定元素提取值.
我有以下 css 和 html ...
.hide
{
display:none;
}
<div>
<span class='kardashian hide'>Kimmy</span>
</div>
Run Code Online (Sandbox Code Playgroud)
使用以下 jquery。
$('div').live('click', function(){
alert($('kardashian', this).val());
});
Run Code Online (Sandbox Code Playgroud)
如果我删除“隐藏”类,我会像预期的那样得到“Kimmy”,但是当它具有“隐藏”类时,我什么也得不到?如何在 Jquery 中获取隐藏元素的文本?
我是 C# 和 .NET 的新手。我正在学习 ASP.NET MVC 5。我发现自己花了额外的时间将模型转换为视图模型的一件事。
这是我的模型
public class Overview
{
public string chain_name { get; set; }
public int store_id { get; set; }
public int total_attempts { get; set; }
public int total_unique_number_called { get; set; }
public int total_callable { get; set; }
public int total_completed_interviews { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的视图模型
public class OverviewViewModel
{
public string chain_name { get; set; }
public int store_id { get; set; }
public int total_attempts { get; …Run Code Online (Sandbox Code Playgroud) 我正在尝试检索计算机名称列表以及它们上次从Active Directory登录的日期,并将它们返回到数据表中.获取名称很容易但是当我尝试添加"lastLogon"或"lastLogonTimestamp"时,如下所示,我获得的lastLogonTimestamp的唯一值是"System._ComObject"
public DataTable GetListOfComputers(string domainName)
{
DirectoryEntry entry = new DirectoryEntry("LDAP://DC=" + domainName + ",DC=com");
DirectorySearcher search = new DirectorySearcher(entry);
string query = "(objectclass=computer)";
search.Filter = query;
search.PropertiesToLoad.Add("name");
search.PropertiesToLoad.Add("lastLogonTimestamp");
SearchResultCollection mySearchResultColl = search.FindAll();
DataTable results = new DataTable();
results.Columns.Add("name");
results.Columns.Add("lastLogonTimestamp");
foreach (SearchResult sr in mySearchResultColl)
{
DataRow dr = results.NewRow();
DirectoryEntry de = sr.GetDirectoryEntry();
dr["name"] = de.Properties["Name"].Value;
dr["lastLogonTimestamp"] = de.Properties["lastLogonTimestamp"].Value;
results.Rows.Add(dr);
de.Close();
}
return results;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用像LDP这样的工具查询AD,我可以看到该属性存在并填充了数据.我怎样才能获得这些信息?
当我创建一个控制台应用程序时,我可以在Visual Studio 2008 Pro中右键单击该项目.单击属性>转到设置,输入应用程序范围设置,然后从代码中访问它
Console.WriteLine(Properties.Settings.Default.MySetting.ToString());
Run Code Online (Sandbox Code Playgroud)
当我在类项目中执行相同的操作并尝试将Applicatin范围设置分配给变量之类的
this.mySettingVariable = Properties.Settings.Default.MySetting.ToString();
Run Code Online (Sandbox Code Playgroud)
在构建"当前上下文中不存在名称'属性'时,我收到错误."
我做错了什么以及如何访问类项目的Application Scoped属性?
我有以下代表
delegate void UpdateFileDelegate(long maxFileID);
Run Code Online (Sandbox Code Playgroud)
我是这样从WinForms应用程序调用的
UpdateFileDelegate FD = new UpdateFileDelegate(ClassInstance.UpdateFile);
FD.BeginInvoke(longIDNumber,null,null);
Run Code Online (Sandbox Code Playgroud)
它以异步方式运行,但我遇到的问题是如何判断Method何时完成执行,以便让最终用户知道?
更新:感谢以下建议,以下代码可以解决问题.此文章也有助于我了解我的代码实际上在做什么.
delegate void UpdateFileDelegate(long maxFileID);
UpdateFileDelegate FB = new UpdateFileDelegate(ClassInstance.UpdateFile);
AsyncCallback callback = new AsyncCallback(this.CallBackMethod);
IAsyncResult result = FB.BeginInvoke(longIDNumber);
private void CallBackMethod(IAsyncResult result)
{
AsyncResult delegateResult = (AsyncResult)result;
UpdateFileDelegate fd = (UpdateFileDelegate)delegateResult.AsyncDelegate;
fd.EndInvoke(result);
MessageBox.Show("All Done!");
}
Run Code Online (Sandbox Code Playgroud) 如果我有一个非常简单的这样的整数.
enum alignment { left, center, right}
Run Code Online (Sandbox Code Playgroud)
我希望数据类型为int,我理解为默认值,并且值为left = 0,center = 1,right = 2.
但是,如果我尝试使用枚举中的值,就像
header.Alignment = alignment.center;
Run Code Online (Sandbox Code Playgroud)
我被告知我需要将alignment.center转换为int.这不是什么大问题,但我想知道我做错了什么,或者只是枚举的方式.
我有一个ashx页面,它返回以下JSON数据,我希望能够循环并将值添加到ul中的一堆li中.
我的问题是如何循环检索值.
从ashx返回的数据看起来像这样
{"ImageCollection":
{
"Images":
[
{
"ImageID":"62",
"CatID":"1",
"Location":"/Images/62.gif",
"FullHeight":"466","FullWidth":"606"
},
{
"ImageID":"63",
"CatID":"1",
"Location":"/Images/63.gif",
"FullHeight":"205",
"FullWidth":"751"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
如果我试试这个
<script type="text/javascript">
$.getJSON("/Service/GetJson.ashx?data=images", function(data) {
var jsObjectData = eval(data);
$.each(data, function(i, item) {
alert(data[i].ImageID);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我得到一个单独的警报,表示未定义.我究竟做错了什么?
有没有办法循环遍历类的构造函数中的所有属性,所以我可以设置所有的默认值,而不是像列出每个属性一样
this.prop1 = "?";
//repeat for each prop
Run Code Online (Sandbox Code Playgroud)
例如:
public class thisClass()
{
library()
{
foreach (property as p in thisClass)
{
p.value = "?";
}
}
public string prop1 {get; set;}
public string prop2 {get; set;}
etc.
}
Run Code Online (Sandbox Code Playgroud) 我从服务器中获取了一些Json,我在dom中动态构建一个表.当有多个对象时,数据将作为对象数组返回,如下所示:
{
"ProductList": {
"Products": [{
"ProductID": "1",
"Name": "ProdName"},
{
"ProductID": "2",
"Name": "ProdName2"}]
}
}
Run Code Online (Sandbox Code Playgroud)
但是当只有一个对象时,它只是作为一个对象而不是像这样的数组返回:
{
"ProductList": {
"Products": {
"ProductID": "3",
"Name": "ProdName3"
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我一直在做的是检查它是否是这样的数组:
if ($.isArray(productDetails.ProductList.Products) === true) {
for (i = 0; i < productDetails.ProductList.Products.length; i++) {
//Create the dom elements by accessing the object properties with [i]
//ie. productDetails.ProductList.Products[i].ProductsID
}
}
else {
//Create the dom elements by accessing the object properties w/o [i]
//ie. productDetails.ProductList.Products.ProductsID
}
Run Code Online (Sandbox Code Playgroud)
它工作但我有很多代码完全相同,除了访问对象属性的方式,每当我改变一个我需要记住改变另一个或我将有问题.客户端是他们处理这个问题的更好方法吗?
c# ×7
jquery ×3
asp.net ×2
.net ×1
asp.net-mvc ×1
asynchronous ×1
delegates ×1
enums ×1
javascript ×1
json ×1
json.net ×1
winforms ×1