本文介绍了找不到路径'd:\abc\bs_db.mdb'的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我遇到了一个非常简单的错误,但无法找到解决方案。

我只需要将文件从一个位置复制到另一个位置。



Hello,
I am stuck with a very simple error, but couldnot finf solution for it.
I just need to copy file from one location to other.

try
            {
                System.IO.FileInfo f = new System.IO.FileInfo(System.IO.File.ReadAllText(Application.StartupPath + "\\con1.txt"));
                if (f.Exists)
                {
                    System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(OMS_Security_Panel.Default_BackupPath);
                    if (!d.Exists)
                        d.Create();
                    f.CopyTo(OMS_Security_Panel.Default_BackupPath + "\\" + DateTime.Now.ToString("yyyymmdd")+ ".mdb", true);
                }
            }
            catch (Exception ce)
            {
                MessageBox.Show(ce.ToString());
            }





当我检查f.exits时它返回true。但是在使用copyto()进行复制时我得到的错误无法找到文件的一部分。



我检查了源路径和目标路径。它也不是权限异常。



when I check for f.exits it returns true. But while copying using copyto() I get error could not find part of file.

I checked both source and destination path. It is also not permission exception.

推荐答案

string inFile = "not assigned";
string outFile = "not assigned";
try
    {
    inFile = System.IO.File.ReadAllText(Application.StartupPath + "\\con1.txt");
    System.IO.FileInfo f = new System.IO.FileInfo(inFile);
    if (f.Exists)
        {
        outFile = OMS_Security_Panel.Default_BackupPath + "\\" + DateTime.Now.ToString("yyyymmdd") + ".mdb";
        System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(OMS_Security_Panel.Default_BackupPath);
        if (!d.Exists)
            d.Create();
        f.CopyTo(outFile, true);
        }
    }
catch (Exception ce)
    {
    MessageBox.Show(String.Format("Could not copy file: \"{0}\"\nTo \"{1}\"\nThe error was: \"{2}\"", inFile, outFile, ce.ToString()));
    }

确保您没有意外地引入了一对虚假的反斜杠或类似物。如果可行,请尝试使用简化文件夹中的固定文件替换inFile和OutFile

Make sure that you haven't accidentally introduced a spurious pair of backslashes or similar. If that works, try replacing inFile and OutFile with fixed files from simplified folders

"D:\Temp\Source.txt"
"D:\Temp\Dest.mdb"



如果可行,则展开直到进入真实文件夹。我怀疑这可能是一个权限问题,因为你的应用程序正在复制它们的用户,而不是你期望的用户 - 但是这比发现一条糟糕的路径更难发现。


If that works, then expand until you get to the "real" folders. I suspect it may be a permissions problem in that the user your app is copying them as is not the user you expect - but that's harder to spot than a bad path.


这篇关于找不到路径'd:\abc\bs_db.mdb'的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 22:57