Windows service in .net

dsk1234
dsk1234 used Ask the Experts™
on
I need some direction to write the code for window service in .net.

My requirement is to move all the files from x folder to y folder for every 2 hours
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
In this tutorial you it is describing how to write a Windows service

http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx?msg=2104238

This describes how to move files

http://msdn.microsoft.com/en-us/library/cc148994.aspx

To do it in a time interval use a timer control in side the service set the interval as you want.

This is how you can do it

http://www.aspfree.com/c/a/C-Sharp/Timer-Objects-in-Windows-Services-with-C-sharp-dot-NET/

Author

Commented:
       
Hi ,

I am able to copy files and subdirectories from one folder to other ,but I need to move files and subdirectories to other folder

Here is the code for copying files and subdirectories to other folder which is working fine.

Can any one help me to just modify below code that will move files and subfolders to other folder

 and also while moving check if any file is being used by any another process we need to skip that file

and move other files   ?

button cick event

             string src="D:\\SRC";
            string dest="D:\\DEST";
            copydirectory(src,dest);


 public static void copydirectory(string s,string d)
        {

            string [] files;

            if(d[d.Length -1]!=System.IO.Path.DirectorySeparatorChar)
                d+=System.IO.Path.DirectorySeparatorChar;

            if(!System.IO.Directory.Exists(d))
                System.IO.Directory.CreateDirectory(d);

            files=System.IO.Directory.GetFileSystemEntries(s);

            foreach (string element in files )
            {
             
               
                if (System.IO.Directory.Exists(element))

                    copydirectory(element, d + System.IO.Path.GetFileName(element));


                else
                     System.IO.File.Copy(element,d+System.IO.Path.GetFileName(element),true);
 
            }


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial