我有一个路径合并的函数。例如:
我的应用程序位于 D:\toto\titi\tata\myapplication.exe
我创建了一个基于我的应用程序路径(D:\toto\titi\tata\myapplication.exe
)解决相对路径的Windows窗体应用程序(C#)。
我想要做到这些:
1)需要解决的路径为test.txt => D:\toto\titi\tata\test.txt
2)需要解决的路径为.\..\..\test\test.txt => D:\toto\test\test.txt
3)需要解决的路径为.\..\test\test.txt => D:\toto\titi\test\test.txt
4)需要解决的路径为.\..\..\..\test\test.txt => D:\test\test.txt
5)需要解决的路径为.\..\..\..\..\test\test.txt => 路径不存在
6)需要解决的路径为\\server\share\folder\test => 获取服务器上对应的路径
我使用了这个方法
private void btnSearchFile_Click(object sender, EventArgs e)
{
// Open an existing file, or create a new one.
FileInfo fi = new FileInfo(@"D:\toto\titi\tata\myapplication.exe");
// Determine the full path of the file just created or opening.
string fpath = fi.DirectoryName;
// First case.
string relPath1 = txtBoxSearchFile.Text;
FileInfo fiCase1 = new FileInfo(Path.Combine(fi.DirectoryName, relPath1.TrimStart('\\')));
//Full path
string fullpathCase1 = fiCase1.FullName;
txtBoxFoundFile.Text = fullpathCase1;
}
但我没有解决1)点、5)点和6)点。你能帮我吗?