Database Backup Routine - From VB2005 to C# 2005

jcrcarmo

Active member
Joined
Dec 14, 2005
Messages
32
Hello folks,

The transition from VB.Net 2005 to C# 2005 is not always a smooth proccess, even though the synthax is almost identical in some cases. The code below exemplifies a MS Access Database Backup routine Im trying to tranlsate to C# 2005:

---------------------------------------------------------------------------------------------------------
Code:
    Private Sub BackupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupToolStripMenuItem.Click

        Dim Time As String = Format(Now, " dddd dd-MM-yyyy
 
Last edited by a moderator:
Probably the closest literal conversion is
C#:
private void BackupToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
{
string Time = DateTime.Now.ToString(" dddd dd-MM-yyyy
 
Last edited by a moderator:
Dear PlausiblyDamp,

The tweaked code didnt work, but your literal translation of the code I posted worked out beautifuly.

By the way, I will be more careful when I create new threads by paying attention to the correct subforum they are supposed to go to.

Thank you very very much for your kind help and have a great day!

Best regards,

JC :)
 
Last edited by a moderator:
I could be wrong, but I think what PlausiblyDamp meant was...
C#:
System.IO.File.Copy(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "myDB.mdb"), SavePath + FileName, true);
but I see no reason this cant be shortend to
C#:
System.IO.File.Copy(System.IO.Path.Combine(Application.StartupPath, "myDB.mdb"), SavePath + FileName, true);
Also its worth noting that my VisualStudio doesnt recognise the following, perhaps its not part of the 1.1 framework?
C#:
Environment.SpecialFolder.MyDocuments
 
Ignore the code above, try the following - you just need to shove a using System.IO at the top of the source file.
C#:
private void BackupToolStripMenuItem_Click(System.Object sender, System.EventArgs e)
{
string Time = DateTime.Now.ToString(" dddd dd-MM-yyyy
 
Dear PlausiblyDamp,

The last code youve posted works great! Thanks a lot for your time and help. It was very educational.

Bye for now,

JC :)
 
Back
Top