I have created a simple form in C# with few buttons and text boxes. User will enter various details such as project description and code number, output file location etc.
End user will have a browse button enabled to allow him/her to select an input directory where the reports are located.
The browse button uses FolderBrowserDialog and checks the result. If result is OK then I have created an array with paths to all the file using locationArray = Directory.GetFiles(fbd.SelectedPath, "*.txt");
The class is defined as public void.
My plan was to add some script into finish button who would then go through the array, extract file names, read the content of each file and produce report with various details.
The problem I'm having is that I cannot seem to access the array in another class(finish button).
I have defined the array before the class - string[] locationArray;
Then with the class I populate the array with file paths as per below:
locationArray = Directory.GetFiles(fbd.SelectedPath, "*.txt");
At this stage I know the array is being populated as I have displayed length of the array.
Can someone advice how do I access the array under different class so I can loop through it please.
Thanks in advance.
To be more specific my code looks like this:
string[] locationArray;
public void button1_Click_1(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Browse Directory";
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
locationArray = Directory.GetFiles(fbd.SelectedPath, "*.txt");
}
FinishButton.Enabled = true;
}
trying to access locationArray in here:
private void button1_Click(object sender, EventArgs e)
{
string sProjectName = ProjectName.Text;
string sProjectNumber = ProjectNumber.Text;
string sOutputDirectory = OutputDirectory.Text;
const string message1 = "Done!";
const string caption1 = "Completed";
var result = MessageBox.Show(message1, caption1,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
if (result == DialogResult.OK)
Environment.Exit(0);
}
Hope this makes it clearer.
Tom