string Current = Directory.GetCurrentDirectory();//获取当前根目录
//private string strFilePath = Application.StartupPath + "\\" + "FileConfig.ini";//获取INI文件路径

//MessageBox.Show("strFilePath: "+strFilePath);
//MessageBox.Show("Application.StartupPath: " + Application.StartupPath+"\\");
//MessageBox.Show("Current: "+Current);
//MessageBox.Show("ExecutablePath: " + System.Windows.Forms.Application.ExecutablePath.ToString());
//MessageBox.Show("目录名称:{0}", Path.GetDirectoryName(strFilePath));
//MessageBox.Show("路径扩展名:{0}", Path.GetExtension(strFilePath));
//MessageBox.Show("文件名:{0}", Path.GetFileName(strFilePath));
//MessageBox.Show("不带扩展名的名称:{0}", Path.GetFileNameWithoutExtension(strFilePath));
//MessageBox.Show("绝对全路径:{0}", Path.GetFullPath(strFilePath));
//MessageBox.Show("根目录:{0}", Path.GetPathRoot(strFilePath));
//MessageBox.Show("不带根目录的路径:{0}", Path.GetFullPath(strFilePath).Remove(0, 3));
//MessageBox.Show(System.Windows.Forms.Application.StartupPath);
//MessageBox.Show(strFilePath);
//MessageBox.Show(Application.ExecutablePath);
//MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
//MessageBox.Show(Thread.GetDomain().BaseDirectory);
//MessageBox.Show(Environment.CurrentDirectory);
//MessageBox.Show(Directory.GetCurrentDirectory());
//MessageBox.Show(Assembly.GetExecutingAssembly().Location);

C# .NET 获取路径信息

C# .NET 获取路径信息

Application.StartupPath  // 获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。 

 Application.ExecutablePath  // 获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。  
AppDomain.CurrentDomain.BaseDirectory  // 获取基目录,它由程序集冲突解决程序用来探测程序集。  
Thread.GetDomain().BaseDirectory  // 获取基目录,它由程序集冲突解决程序用来探测程序集。 
 Environment.CurrentDirectory  // 获取或设置当前工作目录的完全限定路径。  
Directory.GetCurrentDirectory()  // 获取应用程序的当前工作目录。  
Assembly.GetExecutingAssembly().Location // 获取包含清单的已加载文件的路径或 UNC 位置。

通过Request属性获取:

// 获取当前正在执行的服务器应用程序的根目录的物理文件系统路径。

Request.PhysicalApplicationPath;    // E:\解决方案\项目\// 获取与请求的 URL 相对应的物理文件系统路径。 
Request.PhysicalPath;   // E:\\解决方案\项目\zz\zz.aspx

获取虚拟路径和URL信息:(URL:http://localhost/aspnet/zz/zz.aspx/info?name=wk )

// 获取服务器上 ASP.NET 应用程序的虚拟应用程序根路径:/Request.ApplicationPath;// /aspnet  // 获取应用程序根的虚拟路径,并通过对应用程序根使用波形符 (~) 表示法使该路径成为相对路径。

Request.AppRelativeCurrentExecutionFilePath;   // ~/zz/zz.aspx  // 获取当前请求的虚拟路径
Request.CurrentExecutionFilePath;// /aspnet/zz/zz.aspxRequest.FilePath;// /aspnet/zz/zz.aspx  // 获取CurrentExecutionFilePath属性中指定的文件名的扩展名。
Request.CurrentExecutionFilePathExtension;  // .aspx   // 获取当前请求的虚拟路径(包括附件路径信息)
Request.Path;// /aspnet/zz/zz.aspx/info  // 获取具有 URL 扩展名的资源的附加路径信息。
Request.PathInfo; // /info  // 获取有关当前请求的 URL 的信息。Request.Url;//http://localhost/aspnet/zz/zz.aspx/inf?name=wk  // 获取当前请求的原始 URLRequest.RawUrl; // /aspnet/zz/zz.aspx/inf?name=wk  // 获取有关客户端上次请求的 URL 的信息,该请求链接到当前的 URL。Request.UrlReferrer;// System.Uri

---------------------------------------------------------------------------------------------

C# Path

using System.IO;

Path类的静态方法:

ChangeExtension 更改路径字符串的扩展名。

Combine(String()) 将字符串数组组合成一个路径。

Combine(String, String) 将两个字符串组合成一个路径。

Combine(String, String, String) 将三个字符串组合成一个路径。

Combine(String, String, String, String) 将四个字符串组合成一个路径。

GetDirectoryName 返回指定路径字符串的目录信息。

GetExtension 返回指定的路径字符串的扩展名。

GetFileName 返回指定路径字符串的文件名和扩展名。

GetFileNameWithoutExtension 返回不具有扩展名的指定路径字符串的文件名。

GetFullPath 返回指定路径字符串的绝对路径。

GetInvalidFileNameChars 获取包含不允许在文件名中使用的字符的数组。

GetInvalidPathChars 获取包含不允许在路径名中使用的字符的数组。

GetPathRoot 获取指定路径的根目录信息。

GetRandomFileName 返回随机文件夹名或文件名。

GetTempFileName 创建磁盘上唯一命名的零字节的临时文件并返回该文件的完整路径。

GetTempPath 返回当前用户的临时文件夹的路径。

HasExtension 确定路径是否包括文件扩展名。

IsPathRooted 获取指示指定的路径字符串是否包含根的值。

程序实例:

static void Main(string[] args)

{

if (args == null || args.Length < 1)

return;

string myPath = args[0];

Console.WriteLine("目录名称:{0}", Path.GetDirectoryName(myPath));

Console.WriteLine("路径扩展名:{0}", Path.GetExtension(myPath));

Console.WriteLine("文件名:{0}", Path.GetFileName(myPath));

Console.WriteLine("不带扩展名的名称:{0}", Path.GetFileNameWithoutExtension(myPath));

Console.WriteLine("绝对全路径:{0}", Path.GetFullPath(myPath));

Console.WriteLine("根目录:{0}", Path.GetPathRoot(myPath));

Console.WriteLine("不带根目录的路径:{0}", Path.GetFullPath(myPath).Remove(0, 3));

Console.ReadKey();

}

 

C# Path 有关于文件路径获取的问题 的方法的更多相关文章

  1. oc 根据文件路径获取文件大小

    第一种封装: -(NSInteger)getSizeOfFilePath:(NSString *)filePath{ /** 定义记录大小 */ NSInteger totalSize = ; /** ...

  2. c++从文件路径获取目录

    场景 c++从文件路径获取目录 实现代码 初始化是不正确的,因为需要转义反斜杠: string filename = "C:\\MyDirectory\\MyFile.bat"; ...

  3. 【原创】ABAP根据文件路径获取文件所在目录(续)

    在上一篇文章<ABAP根据文件路径获取文件所在目录>中,我主要的思路是采用 “SPLIT dobj AT sep INTO TABLE result_tab” 句型将文件全路径按分隔符“\ ...

  4. 使用File类、StreamRead和StreamWrite读写数据、以及Path类操作文件路径和Directory

    1.File类的概念: File类,是一个静态类,主要是来提供一些函数库用的.静态实用类,提供了很多静态的方法,支持对文件的基本操作,包括创建,拷贝,移动,删除和 打开一个文件. File类方法的参量 ...

  5. java项目部署后的文件路径获取

    //eclipse部署工程 String path = request.getServletContext().getRealPath( File.separator+ "WEB-INF&q ...

  6. 【原创】ABAP根据文件路径获取文件所在目录

    *&---------------------------------------------------------------------* *& Form frm_get_pat ...

  7. php文件路径获取文件名

    物理截取: $file = '/www/htdocs/inc/lib.inc.php'; $filename = basename($file); echo $filename, '<br/&g ...

  8. PHP 文件路径获取文件名

    物理截取 $file = '/www/htdocs/inc/lib.inc.php'; $filename = basename($file); echo $filename, '<br/> ...

  9. python 通过文件路径获取文件hash值

    import hashlib import os,sys def CalcSha1(filepath): with open(filepath,'rb') as f: sha1obj = hashli ...

随机推荐

  1. xml操作-Nested exception: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId. 异常处理

    异常如下: org.dom4j.DocumentException: Error on line 2 of document file:///D:/workspaces/struts2/lesson0 ...

  2. 移动web——轮播图

    1.我们将5张图片又前后各增加一张,第一张前增加的是原本的第五张,第五张后增加的是原本的第一张,增加的原因无非是手指滑动的时候有轮播效果,这不像以前的轮播图,点击图标就能立刻将ul跳转到指定位置,手机 ...

  3. SPA设计架构

    1.SPA是采用单页应用(Single Page Application)的方式来开发 2.SPA的框架有如Augular.js.Vue.js等.

  4. UICollectionView框架总结

    一.UIcollectionView介绍 1.1.简介 首先看苹果官方文档 UICollectionView Class Reference 的介绍: The UICollectionView cla ...

  5. Replacing Threads with Dispatch Queues

    Replacing Threads with Dispatch Queues To understand how you might replace threads with dispatch que ...

  6. .htaccess使用

    RewriteEngine on #请求替换 #test-zhangsan-20 替换为 test.php?name=zhangsan&age=20 RewriteRule test-([a- ...

  7. ESX/ESXi 主机的某些存储阵列可能存在读取或写入性能问题 (1002598)

    Last Updated: 12/14/2018Categories: Troubleshooting  Details 免责声明:本文为 ESX/ESXi hosts might experienc ...

  8. sysbench基准测试工具

    一.简介SysBench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.当前功能允许测试的系统参数有:file I/O performance (文件I ...

  9. php第十六节课

    分页 <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 private $ ...

  10. Linux - redis哨兵集群实例

    目录 Linux - redis哨兵集群实例 命令整理 配置流程 Linux - redis哨兵集群实例 命令整理 官网地址:http://redisdoc.com/ redis-cli info # ...