if (!File.Exists(A.mdb)); 
            { throw new Exception("源数据库不存在"); } 
            try { File.Copy(A.mdb, B.mdb2, true); }
            catch (IOException ixp) 
            { throw new Exception(ixp.ToString()); }
A.mdb这个应该是源数据库的绝对路径吧
我的ACCESS数据库放在了 D:\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\pcdb.mdb,
我想把它备份到G盘跟目录下面,请问代码该如何去修改呢

解决方案 »

  1.   

    File.Copy(@"D:\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\bin\Debug\pcdb.mdb",@"G:\pcdb.mdb");
      

  2.   

    但是又说file不对,说上下文中不存在file!晕了!
      

  3.   

    刚才的是WebFormC/S下的话

    string HomePath = System.Environment.CurrentDirectory;
    //Application.StartupPath的上一级目录。
    string TmpPath = HomePath.SubString(0,HomePath.LastIndexOf("\\")-1)
      

  4.   

    添加引用
    using System.IO;
      

  5.   

    你是Web页面还是winform页面呀
    winform
            string HomePath = System.Environment.CurrentDirectory; 
            string TmpPath = HomePath.SubString(0, HomePath.LastIndexOf("\\") - 1);        File.Copy(TmpPath+@"pcdb.mdb", @"G:\pcdb.mdb");web页面的话,是不可能有权限访问其他目录的
         
            string RootPath = Server.MapPath("数据库文件的相对路径");
            string virtualPath = RootPath + "/dbBackup/";
            if (!Directory.Exists(virtualPath))
            {
                Directory.CreateDirectory(virtualPath);
            }
            File.Copy(RootPath + @"\pcdb.mdb",virtualPath + @"\pcdb.mdb");