Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Error   1 ; System.Linq.Strings' is inaccessible due to its protection level   C:\Users\WinBilling\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs    62  64  WindowsFormsApplication1


C#
private void ButtonRestoreBackup_Click(object sender, EventArgs e)
       {
           try
           {
               OpenFileDialog dlg = new OpenFileDialog();
               dlg.Filter = "Microsoft Access Database(2002-2003) (*.mdb)|*.mdb|Microsoft Access Database(2007-2009) (*.accdb)|*.accdb";
               // If you want to keep default extensiion *.mdb then FilterIndex = 1 or if you want to keep default extension *.accdb then FilterIndex=2
               dlg.FilterIndex = 1;

               if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
               {
                   TextBoxRestoreBackup.Text = dlg.FileName;
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

       private void ButtonRestoreDestination_Click(object sender, EventArgs e)
       {
           try
           {
               FolderBrowserDialog folder = new FolderBrowserDialog();
               if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
               {
                   TextBoxRestoreDestination.Text = folder.SelectedPath;
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

       private void ButtonRestore_Click(object sender, EventArgs e)
       {
           try
           {
               DialogResult result = MessageBox.Show("Do you want to restore the Database?", "Do you?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
               string fileName = null;
               //fileName = (TextBoxRestoreBackup.Text.ToString()); //.Substring(Strings.InStrRev(TextBoxRestoreBackup.Text, "\\"));
               fileName = TextBoxRestoreBackup.Text.Substring(Strings.InStrRev(TextBoxRestoreBackup.Text, "\\"));

               if (result == System.Windows.Forms.DialogResult.Yes)
               {
                   if (System.IO.File.Exists(TextBoxRestoreDestination.Text + "\\" + fileName))
                   {
                       DialogResult resultReplace = MessageBox.Show("This File is already exist. Do you want to replace the Database?", "Do you?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                       if (resultReplace == System.Windows.Forms.DialogResult.Yes)
                       {
                           System.IO.File.Delete(TextBoxRestoreDestination.Text + "\\" + fileName);
                           System.IO.File.Copy(TextBoxRestoreBackup.Text, TextBoxRestoreDestination.Text + "\\" + fileName);
                       }
                   }
                   else
                   {
                       System.IO.File.Copy(TextBoxRestoreBackup.Text, TextBoxRestoreDestination.Text + "\\" + fileName);
                   }
               }
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }
Posted
Updated 13-Aug-13 5:52am
v2
Comments
Maciej Los 13-Aug-13 11:53am    
Please, be more specific and provide more details. What have you done so far? Where are you stuck? Wchich line raises error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900