首页 > 编程语言 >csharp 获取当前程序的所在目录

csharp 获取当前程序的所在目录

时间:2024-04-16 23:00:26浏览次数:24  
标签:Console GetExecutingAssembly System 获取 WriteLine csharp Directory 目录

获取当前程序所在的目录

// 获取当前程序的执行目录信息
Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); // asp.net使用,不过在console下也是 /xxx/bin/Debug/net8.0/
Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().Location); // => /xxx/bin/Debug/net8.0/App.dll
Console.WriteLine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));// => /xxx/bin/Debug/net8.0/
Console.WriteLine(Environment.CurrentDirectory); // 取决于当前执行dotnet run命令的路径
// 获取当前程序的执行目录的父级目录
string currentDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string parentDirectory = Directory.GetParent(currentDirectory)?.FullName;
string grandparentDirectory = Directory.GetParent(parentDirectory)?.FullName;
Console.WriteLine("Current Directory: " + currentDirectory);
Console.WriteLine("Parent Directory: " + parentDirectory);
Console.WriteLine("Grandparent Directory: " + grandparentDirectory);

标签:Console,GetExecutingAssembly,System,获取,WriteLine,csharp,Directory,目录
From: https://www.cnblogs.com/zhuoss/p/18139499

相关文章

  • C:\Windows\servicing\Packages 是一个存储 Windows 更新程序包的目录。Windows 操
    C:\Windows\servicing目录包含了与Windows维护和更新相关的文件和子目录。让我们逐个解释一下每个子目录和文件的作用:CbsApi.dll和CbsMsg.dll:这两个DLL文件是Windows组件基础服务(CBS)的一部分。CBS是Windows中用于安装、卸载、维护和更新组件的服务。这些D......
  • allfiles.vbs 显示子目录下的所有文件的修改时间、大小、文件名、扩展名等
    <p>&#65279;有的时候将子目录下的所有文件的修改时间、大小、全限定名等信息导出到Excel表格中。</p>尝试过命令行,但不太好用——1.对于“dir/s>1.txt”,当前目录与文件列表是分开显示的,合并起来太麻烦,而且没有文件的全限定名。2.对于“dir/b/s>1......
  • vbs获取操作系统及其版本号
    <h2>vbs获取操作系统及其版本号</h2>'**************************************'*byr05e'*操作系统及其版本号'**************************************strComputer="."SetobjWMIService=GetObject("winmgmt......
  • net6 类中获取服务
    第一种实现方式(不推荐)varservices=newServiceCollection();varprovider=services.BuildServiceProvider();var_demoService=provider.GetService<IDemoService>();varservices=newServiceCollection();varprovider=services.BuildServiceProvider();v......
  • 如何在Rust程序项目中安全地使用外部或是项目目录下的文件?
    在开发程序的时候难免会需要在程序中引入外部的文件,为了方便管理我们也常会将这些文件放置在程序项目目录下。然而在代码撰写程序路径于运行阶段读取文件时,文件路径的正确性需要等到运行阶段的时候才会知道,就算写错了而找不到这个文件,程序项目也是能成功通过编译,这就会使得程序在......
  • csharp selenium HtmlAgilityPack 爬虫 网页解析 微信公众号
    Wechat.Crawler/App/App.csproj<ProjectSdk="Microsoft.NET.Sdk"><ItemGroup><ProjectReferenceInclude="..\Blog\Blog.csproj"/></ItemGroup><ItemGroup><NoneUpdate="nlog.config&......
  • openGauss Anomaly-detection-异常检测获取帮助
    获取帮助模块命令行说明:gs_dbmindcomponentanomaly_detection--help显示如下帮助信息:usage:anomaly_detection.py[-h]--action{overview,plot}-cCONF-mMETRIC-sSTART_TIME-eEND_TIME[-HHOST][-aANOMALY]WorkloadAnomalyd......
  • openGauss Anomaly-analysis-获取帮助
    获取帮助模块命令行说明:gs_dbmindcomponentanomaly_detection--help显示如下帮助信息:usage:anomaly_analysis.py[-h]-cCONF-mMETRIC-sSTART_TIME-eEND_TIME-HHOST[--csv-dump-pathCSV_DUMP_PATH]WorkloadAnomalyanalysis:A......
  • LayUI弹窗确定后获取子页面的值(如获取UEditor富文本的内容,或input标签内容)
    LayUI弹窗确定后获取子页面的值(如获取UEditor富文本的内容,或input标签内容)子窗体JS代码<scriptsrc="~/lib/ueditor-1.4.3.3/ueditor.config.js"></script><scriptsrc="~/lib/ueditor-1.4.3.3/ueditor.all.js"></script><script>varue=UE.......
  • 获取layui表格(table)当前页的页码值和当前页的数据条数
    获取layui表格(table)当前页的页码值和当前页的数据条数在浏览器查看源码,获取当前页面的数据条数如下核心代码$(".layui-laypage-limits").find("option:selected").val()//分页数目$(".layui-laypage-skip").find("input").val()//当前页码值//转载请保留原创地址http:......