I have a Windows Service syncing files between local folder and fileshare folder. Windows Service runs on a local system. When I run it with both folders on the same computer, it works fine. But when I put fileshare folder on another computer, it throws an error "The directory name is invalid".
I have tried to reach the fileshare folder on other computer manually with shortcut, and no problems with that.
Any suggestions?
Attaching the code:
private readonly string _localFolderPath = @"C:\Users\vernenat\OneDrive\Desktop\localfolder";
private readonly string _fileSharePath = @"\\MyComputerName\fileshare";
private readonly string _logFolderPath = @"C:\Users\vernenat\OneDrive\Desktop\logfolder";
private readonly FileSystemWatcher _localWatcher = new FileSystemWatcher();
private readonly FileSystemWatcher _fileShareWatcher = new FileSystemWatcher();
private static object logFileLock = new object();
public Service1()
{
InitializeComponent();
}
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
protected override void OnStart(string[] args)
{
try
{
WriteToLogs($"{DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss.fff")} Service was started");
WriteToLogs($"{DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss.fff")} Setting up local folder watcher");
_localWatcher.Path = _localFolderPath;
_localWatcher.IncludeSubdirectories = true;
_localWatcher.EnableRaisingEvents = true;
_localWatcher.Created += OnChangedLocal;
WriteToLogs($"{DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss.fff")} Setting up file share folder watcher");
_fileShareWatcher.Path = _fileSharePath;
_fileShareWatcher.IncludeSubdirectories = true;
_fileShareWatcher.EnableRaisingEvents = true;
SyncFilesFromLocal();
SyncFilesFromFileshare();
}
catch (Exception ex)
{
WriteToLogs(ex.ToString());
}
}
Expected Windows Service with fileshare folder on another computer to work without errors, as locally everything was fine, but got an error "The directory name is invalid"