c# - How to Copy a file to Network Location from Windows Service? -


I have a Windows service running on a Windows Server 2008 server that will monitor a directory on the local server (i.e. : \ Watch) and when a new PDF is created in that directory, copy the file onto the network share (i.e.11.168.1.2 / share).

The server is neither a member of the domain.

The Windows service is logged on to the local user account, which is not a problem in accessing / server / share / accessing and removing files.

I have the following which works fine if sourceDir and destDir local folders like C: \ Source and C: \ Dest but if I have destdir a network location like // server / share / or /// / Server / // share / / I get the error "T file name, directory name, or volume label syntax is incorrect".

Update: I have not found the above error now and now when I have set SourceDir to C: \ watch and destDir on \ server \ share \ (where the server Windows may be or Ubuntu Server receives a system I'm having an anonymous asset error that I believe is coming from the destination server.How can I set credentials to use when connecting to the destination server. Not in a domain and windows Public partial service Service: Servicebase {Personal filesystem water watcher; Private string sourcefolder; Private string Dest folder; Public service 1 () {InitializeComponent ();} Safe Run override zero (string [] args) {this.sourceFolder = properties.Settings.Default.sourceDir; This.destFolder = properties.Settings.Default.destDir; watch = new filesystemaver;); Watcher.Path = this.sourceFolder; Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; Watcher.Filter = "* .pdf"; Watcher.Created + = New FileSystemEventHandler (watchercredated); Watcher.EnableRaisingEvents = True; } Secure Override Onstop () {} Private Wide Vectored (Object Source, File System Avengers ARGs) {FileInfo fInfo = new FileInfo (e.FullPath); While (IsFileLocked (fInfo)) {Thread.Sleep (500); } System.IO.File.Copy (e.FullPath, this.destFolder + e.Name); System.IO.File.Delete (e.FullPath); }}

will be part of the server:

  String network share = \ "\\ server name \ share \"; Keep in mind also, the  identity service that will be performing will affect the service that will be saved to that location  If you run a service for the domain service account If you are using, make sure that you adjust the ACL to the destination share folder with the machine that allows to write the share   

Comments