Created
April 24, 2018 11:18
-
-
Save sin2akshay/dcf2393273f385f0703a9247b1c308cb to your computer and use it in GitHub Desktop.
C# - Transfer file from one Folder to other
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Transfer file from one Folder to other | |
/// </summary> | |
/// <param name="path">Path to Target Folder</param> | |
/// <param name="FileName">Full Path to Source File</param> | |
public void TransFileToSpecifiedFolder(string path, string FileName) | |
{ | |
//Deleting file from destination folder if it exists, else exception occurs | |
string path2 = path + "\\" + Path.GetFileName(FileName); | |
try | |
{ | |
LogManager.EventLog("Inside TransFileToSpecifiedFolder: Moving '" + Path.GetFileName(FileName) + "' to '" + path + "'"); | |
if (!Directory.Exists(path)) | |
{ | |
Directory.CreateDirectory(path); | |
} | |
if (File.Exists(path2)) | |
File.Delete(path2); | |
File.Move(FileName, path2); | |
} | |
catch (Exception ex) | |
{ | |
//Log the error to your logger | |
LogManager.EventLog("[Error] Inside TransFileToSpecifiedFolder: " + ex.Message); | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment