I am creating a Windows Forms Application with c# that can open up a file on startup if it is passed an argument containing the path to the file.
However, it doesn't accurately determine if arguments have been passed. Even when I pass no arguments, it still tries to open up a file.
Here's my code:
string[] args = Environment.GetCommandLineArgs();
if (args == null || args.Length == 0)
{
}
else
{
try
{
ListData ld = new LmReader.LmReader().readLmList(args[0]);
listItemsList.Items.Clear();
foreach (ListItemList li in ld.lil)
{
ListViewItem lvi = new ListViewItem(li.text);
lvi.Font = li.itemFont;
listItemsList.Items.Add(lvi);
}
filenameOpen = selectOpenLocation.FileName;
this.Text = "List Maker - " + Path.GetFileNameWithoutExtension(args[0]);
}
catch (Exception ex)
{
new Error().doError("Your list could not be opened.", ex);
}
}
What am I doing wrong?