1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
private void MoveFiles()
{
NetworkShare.ConnectToShare(@"" + SourcePath, SourceLogin, SourcePassword);
try
{
Thread.Sleep(1000);
String[] files = Directory.GetFiles(SourcePath + "\\", "*" + FileType, SearchOption.TopDirectoryOnly);
foreach (String file in files)
{
File.Move(file, DestPath + "\\" + new FileInfo(file).Name);
Library.WriteErrorLog(new FileInfo(file).Name.ToString() + " déplacé vers " + DestPath);
}
}
catch (Exception ex)
{
Library.WriteErrorLog("Service Erreur : " + ex.Message);
//Stop the Windows Service.
using (System.ServiceProcess.ServiceController serviceController = new System.ServiceProcess.ServiceController("SimpleService"))
{
Library.WriteErrorLog("Le Service MoveFile est stoppé");
serviceController.Stop();
}
}
NetworkShare.DisconnectFromShare(@"" + SourcePath, false);
} |
Partager