string pegasusKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Pegasus\";
string opera2ServerPath = @"Server VFP\";
string opera3ServerPath = @"O3 Client VFP\";
string opera2InstallationPath = null;
string opera3InstallationPath = null;
//Gets the opera Installtion paths and reads to the string opera*InstallationPath
opera2InstallationPath = (string)Registry.GetValue(pegasusKey + opera2ServerPath + "System", "PathToServerDynamic", null);
opera3InstallationPath = (string)Registry.GetValue(pegasusKey + opera3ServerPath + "System", "PathToServerDynamic", null);
string Filesource = null;
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
foreach (string File in FileList)
Filesource = File;
label.Text = Filesource;
if (System.IO.Directory.Exists(opera3InstallationPath))
{
System.IO.File.Copy(Filesource, opera3InstallationPath);
MessageBox.Show("File Copied from" + Filesource + "\n to" + opera3InstallationPath);
}
else
{
MessageBox.Show("Directory Doesn't Exist");
}
用户将文件拖到窗口上,然后我获取应用程序的安装路径,然后将其用作源文件的目标。当应用程序运行时,它会抛出找不到的错误目录。但是当然如果目录不存在则应该进入else语句?一个简单的应用程序,变得头疼!
答案 0 :(得分:0)
您的Filesource必须无效。这是我的建议:
另外,我几乎可以肯定你在代码的这一部分有一个逻辑错误..(你一遍又一遍地在一个循环中分配一个变量,你的意思是追加它吗?这没有意义)。
string Filesource = null;
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
foreach (string File in FileList)
Filesource = File;
label.Text = Filesource;