need an help in console application

Posted by Ashpal under C# on 4/21/2011 | Points: 10 | Views : 1593 | Status : [Member] | Replies : 8
Hi all,

how to create a console application which copies a file in specific lets say C:/ filename on system in a network to a server every day at 12 midnight.
Can anyone help?
it should check for
Unable to access system
. Unable to access server
. Unable to access file on system
. Unable to copy file from system


Thanks in advance

Ashpal




Responses

Posted by: Ashpal on: 4/21/2011 [Member] Starter | Points: 25

Up
0
Down
How to check for exceptions


Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 4/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

You can use the FIle Copy as bellow.

string Sourcepath = @"C:\\[Folder]";
string DestinationPath=@"\\[IP/Machine Name]\[Folder]";
string FileName = "[File Name]";
try
{
Sourcepath = Path.Combine(Sourcepath, FileName);
DestinationPath = Path.Combine(DestinationPath, FileName);
File.Copy(Sourcepath, DestinationPath, true);
}
catch (UnauthorizedAccessException ex)
{
Console.WriteLine(ex.Message);
}
catch (ArgumentNullException ex)
{
Console.WriteLine(ex.Message);
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
}
catch (DirectoryNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
catch (IOException ex)
{
Console.WriteLine(ex);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

And one more thing if you are creating a console, then configure the windows scheduler to run this application at 12 midnight

Else

Create a windows service for this.

Thanks,
Debata

Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ashpal on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Debata,

Wow, thank you so much Debata...
The file that should get copied should be the second latest file in the given folder
Can you help ?

Thanks in advance...
I really appreciate your help
Ashwini




Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

Could you please explain a bit about you requirement?



Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Use the following code
DirectoryInfo dinfo = new DirectoryInfo("<Source Directory Path>");

FileInfo finfo=dinfo.GetFiles().OrderByDescending(f => f.CreationTime).Skip(1).FirstOrDefault();
Console.Write(finfo!=null?finfo.FullName:"No 2nd Latest File found");




Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ashpal on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
I have to write an console application which backups a second latest file in a given C:\name directory on a system to a server's C:\name everyday at 12 am and it should give back messages if it fail for given exceptions
Unable to access system
. Unable to access server
. Unable to access file on system
. Unable to copy file from system

Thanks

Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ashpal on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
I have to write an console application which backups a second latest file in a given C:\name directory on a system to a server's C:\name folder everyday at 12 am if that file is not there in server folder and also it should give back messages if it fail for given exceptions
Unable to access system
. Unable to access server
. Unable to access file on system
. Unable to copy file from system

Thanks

Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 4/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

Take a look at my last reply above, that code can be used to get the FullName of the second latest file in a particular folder,use that file name as the sourcefile name in my previous post.


Thanks,
Debata

Ashpal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response