我已经发现了这个文件夹C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files并且有一些问题.
我试图使用下面的代码获取控制台应用程序的目录,
Assembly.GetExecutingAssembly().Location
Run Code Online (Sandbox Code Playgroud)
但是这个给了我汇编所在的位置.这可能与我执行应用程序的位置不同.
我的控制台应用程序解析没有参数的日志.它必须转到logs/可执行文件夹中的文件夹,或者如果我给它一个路径来logs/解析它.
我有一个配置文件app.exe.config和appSettings部分有这样的:
<configuration>
<appSettings configSource="app.file.config" />
</configuration>
Run Code Online (Sandbox Code Playgroud)
app.file.config文件有这样的东西:
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="var1" value="value 1" />
<add key="var2" value="value 2" />
<add key="var3" value="value 3" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
我需要在运行时编辑var1,var2和var3,我有这样的代码:
Configuration config = ConfigurationManager.OpenExeConfiguration("...path\app.exe);
config.AppSettings.SectionInformation.ConfigSource = "app.file.config";
config.AppSettings.Settings["var1"].Value = "value 11";
config.AppSettings.Settings["var2"].Value = "value 22";
config.AppSettings.Settings["var3"].Value = "value 33";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Run Code Online (Sandbox Code Playgroud)
当我运行config.Save ....文件app.file.config有一个appSettings节点,其属性为"file".此属性具有app.file.config的值
<appSettings file="app.file.config">
<add key="var1" value="value 1" />
<add key="var2" value="value 2" />
<add key="var3" value="value 3" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试加载配置文件,我有一个例外,消息"无法识别的属性'文件'.请注意,属性名称区分大小写." 在app.file.config中.
如果手动删除文件属性,则会正确加载配置文件.
有任何想法吗?
保存配置文件时如何避免写入文件属性.
谢谢
我有一个Uri对象被传递给我的类的构造函数.
我想打开文件的Uri指向,无论是本地,网络,http,无论如何,并将内容读入字符串.有没有一种简单的方法可以做到这一点,或者我是否必须尝试解决一些问题,想Uri.IsFile弄清楚如何尝试打开它?
我有一个 ASP.Net Core 3.1 解决方案,它使用 Docker Compose 文件作为其启动项目。从代码中的任何位置调用该方法Directory.GetCurrentDirectory()都会返回 string /app,这很奇怪,因为我期望该字符串包含/bin/Debug/netcoreapp3.1or (Release如果我在发布模式下构建代码)。如果我进入运行代码的 docker 容器,执行代码位于/app/bin/Debug/netcoreapp3.1.
到底是怎么回事?
我想做的是获取我的excel文件的文件路径.但我无法这样做.
文件位于Document/Visual Studio 2013/Project/ProjectName/a.xlsx中
string path = Path.Combine(HttpContext.Current.Server.MapPath("~/"),"a.xlsx");
string SheetName="Sheet1";
Run Code Online (Sandbox Code Playgroud)
这样做是错误的还是正确的方法?
我在C#中调用一个方法如下:
return Chart.RenderChartHTML("../../Charts/MSLine.swf");
Run Code Online (Sandbox Code Playgroud)
问题是路径可能会有所不同,具体取决于我从哪个文件夹调用RenderChartHTML.
我尝试了以下内容,以便找到绝对路径但不工作:
string mslinepath = HttpContext.Current.Server.MapPath("~/Charts/MSLine.swf");
return Chart.RenderChartHTML(mslinepath);
Run Code Online (Sandbox Code Playgroud) 我有一个位于桌面上的控制台应用程序.我已将其设置为计划任务,每20分钟无限期运行一次.我已经关闭了自动睡眠/休眠状态.然后我打开电脑并锁定桌面周末(2-3天).
我的控制台应用程序是在每次捕获异常时通过电子邮件发送给我的.当我退回时,检查我的收件箱收到了几封包含的错误电子邮件
访问路径'C:\ WINDOWS\system32\myLogs \'被拒绝.
似乎我的控制台应用程序是从System32不是从我的运行Desktop.
问:为什么它表现得像?
这是我创建myLog文件夹路径的字符串
var logpath = Directory.GetCurrentDirectory() + Properties.Settings.Default.LogPath;
Run Code Online (Sandbox Code Playgroud)
这将检查文件夹是否存在,如果不存在则创建新文件夹.
if (!Directory.Exists(logpath))
Directory.CreateDirectory(logpath);
Run Code Online (Sandbox Code Playgroud)
我相信在检查/创建文件夹时触发了错误.我的应用程序应该myLog在与控制台应用程序相同的目录中创建该文件夹.
问:为什么它从System32文件夹运行?
如何执行命令:
adb.exe kill-server
Run Code Online (Sandbox Code Playgroud)
对于位于解决方案本身的文件?
我在环境变量中将adb添加到PATH后才执行:
private string implementCommandLine(string fileName, string param)
{
string output = "";
ProcessStartInfo startInfo = new ProcessStartInfo(fileName, param)
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
Process adbProc;
adbProc = Process.Start(startInfo);
using (StreamReader myOutput = adbProc.StandardOutput)
{
output = myOutput.ReadToEnd();
}
return output;
}
Run Code Online (Sandbox Code Playgroud)
我也试过获取位于Files文件夹中的adb.exe的路径
但是这条路真的太混乱了,我无法成功!
仍然当我执行"Files/adb.exe [params]"时,我收到此错误:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
Run Code Online (Sandbox Code Playgroud)
例外细节:
我已经构建了ac#代码,它基本上需要四个参数a1 a2 a3 a4.我正在尝试创建一个批处理文件,以便用户可以输入他的参数和代码给出特定的输出.我不知道如何将这些参数发送到批处理文件.我尝试创建exe但它似乎不起作用.