TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
lelo nyaka
NA
90
2.7k
How can i resolve path in c#
Feb 9 2015 8:36 AM
Hello ,i have a function which combine path.
Example
My application is located in D:\toto\titi\tata\myapplication.exe
And I create a windows form application(c#) which solve the relative path based on the path of my application (D:\toto\titi\tata\myapplication.exe).
I want to this this :
1)Path to resolve is test.txt => D:\toto\titi\tata\test.txt
2)Path to resolve is .\..\..\test\test.txt => D:\toto\test\test.txt
3)Path to resolve is .\..\test\test.txt => D:\toto\titi\test\test.txt
4)Path to resolve is .\..\..\..\test\test.txt => D:\test\test.txt
5)Path to resolve is .\..\..\..\..\test\test.txt => The path doesn't exist
6)Path to resolve is \\server\share\folder\test => get the corresponding path in the server.
I use this method
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;
}
but i doesn't solve point 1);point 5) and point 6)
Can you help me
Reply
Answers (
4
)
How to edit from the datagridview and save new changes
Xlsx to xml