Newbie Question - Scan
Is there a way to make my program scan its directory for all the .dll files it needs to run? At the moment if there's a file missing it crashes but i want to add an exception that will bring up a message box to tell me which file is missing before the program attempts to run?

FroglegRank #1,020 · 1.9K reputationPosted Jan 11, 2011, 9:11 AM EST
string[] myDlls = new string[5];
bool dllOK = true;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chkDll();
if (dllOK == false)
{
//stop something
}
}
public void chkDll()
{
myDlls[0] = (Application.StartupPath + "\\test1.dll");
myDlls[1] = (Application.StartupPath + "\\test2.dll");
myDlls[2] = (Application.StartupPath + "\\test3.dll");
myDlls[3] = (Application.StartupPath + "\\test4.dll");
myDlls[4] = (Application.StartupPath + "\\test5.dll");
foreach (string f in myDlls)
{
if (File.Exists(f) == false)
{
string fp = Path.GetFileName(f);
MessageBox.Show("Required file is missing " + '"' + fp + '"');
dllOK = false;
}
}
}
Keenan Molver3 reputationPosted Jan 11, 2011, 10:16 AM EST
Was having trouble but then it was a stupid mistake on my side, was referencing (thinks thats the right term) the dlls in the Form1_Load and not in the methods which required them so I just moved them to their respective methods and now its working hundreds.
Thanks again :)
Sam HobbsRank #107 · 20.5K reputationPosted Jan 12, 2011, 5:17 AM EST