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
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
System.IO.Path.Combine to merge File Path
Venkatesan Jayakantham
May 03, 2012
62.8
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
System.IO.Path.Combine to merget file path in c#.
System.IO.Path.Combine to merget file path in c#
Just come across an interesting method
System.IO.Path.Combine
. Thought of sharing with my blog readers. This method is used to merge the path of the file with another string.
string fileName = "test.txt";
string sourcePath = @"C:\Users\Public\TestFolder";
string targetPath = @"C:\Users\Public\TestFolder\SubDir";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
// To copy a folder's contents to a new location:
// Create a new target folder, if necessary.
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
// To copy a file to another location and
// overwrite the destination file if it already exists.
System.IO.File.Copy(sourceFile, destFile, true);
Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech
http://www.kaashivinfotech.com/
System.IO.Path.Combine to merge File Path
Next Recommended Reading
Deleting Internet Cache files from local machine using System.IO in c#