windows services to move files from one folder to another folder
hi all,
im working on windows services. c sharp.
all i hav to do is :
i hav 4 controls . 2 datetime controls and 2 textboxes.
2 datetime controls to accept starttime and endtime.
2 textboxes to accept the sourcefilepath and destinationfile path.
windows service should run all the time. Between the starttime and endtime, files should be copied from the folder in sourcefilepath to the folder in destinationfile path.
i've use app.config to store and retrieve the starttime, endtime,sourcef ilepath and destinationfile path
Following is my Service OnStart method:
Following is my windows form code behind file:
pls can anyone give coding for this task?
hi all,
im working on windows services. c sharp.
all i hav to do is :
i hav 4 controls . 2 datetime controls and 2 textboxes.
2 datetime controls to accept starttime and endtime.
2 textboxes to accept the sourcefilepath and destinationfile path.
windows service should run all the time. Between the starttime and endtime, files should be copied from the folder in sourcefilepath to the folder in destinationfile path.
i've use app.config to store and retrieve the starttime, endtime,sourcef ilepath and destinationfile path
Following is my Service OnStart method:
Code:
protected override void OnStart() { //string from = @"C:\Documents and Settings\Administrator\Desktop\niru\Notepads\From"; //string to = @"C:\Documents and Settings\Administrator\Desktop\niru\Notepads\To"; string startTime = ConfigurationManager.AppSettings["starttime"]; string endTime = ConfigurationManager.AppSettings["endtime"]; string from = ConfigurationManager.AppSettings["from"]; string to = ConfigurationManager.AppSettings["to"]; DateTime startTimeDt = Convert.ToDateTime(startTime); DateTime endTimeDt = Convert.ToDateTime(endTime); DateTime currTimeDt = DateTime.Now; if (currTimeDt >= startTimeDt && currTimeDt <= endTimeDt) { File.Move(from, to); } }
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Configuration; using FileTransferServices; namespace FileTransferWinForm { public partial class FileTranferForm : Form { //FileTransferServices.FileTransferServices fts = new FileTransferServices.FileTransferServices(); //FileTransferProperty ftp = new FileTransferProperty(); public FileTranferForm() { InitializeComponent(); } private void FileTranferForm_Load(object sender, EventArgs e) { //endtime_dtp.Format = DateTimePickerFormat.Time; //endtime_dtp.ShowUpDown = true; string startTime = ConfigurationManager.AppSettings["starttime"]; string endTime = ConfigurationManager.AppSettings["endtime"]; string from = ConfigurationManager.AppSettings["from"]; string to = ConfigurationManager.AppSettings["to"]; //starttime_dtp.Text = startTime; //endtime_dtp.Text = endTime; //frm_txt.Text = from; //to_txt.Text = to; } private void frm_txt_TextChanged(object sender, EventArgs e) { //ftp.From = frm_txt.Text; } private void to_txt_TextChanged(object sender, EventArgs e) { //ftp.To = to_txt.Text; } private void submit_btn_Click(object sender, EventArgs e) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings["starttime"].Value = starttime_dtp.Text; config.AppSettings.Settings["endtime"].Value = endtime_dtp.Text; config.AppSettings.Settings["from"].Value = frm_txt.Text; config.AppSettings.Settings["to"].Value = to_txt.Text; config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }