Reputation: 127
We've been creating a search engine that browses through folders on the computer and transfers the searches to a list box where you can open the files and other subfolders.We're using windows form in C# to code.I have two windows form,one (form1) obtains the searches from the user and the second form (form2) displays the searches.The problem is that in my code my files and folders can't be found because my string path1 is set to null but I have already assigned it to a value in form 2.If you look at the code maybe youll get a clearer understanding of what I mean by path1 and form2.My question is how can I fix this?My friend has the same exact code and it works on her computer but for some reason mines is set to null which is preventing me from opening files and folders.
public static string path1;
private void Form2_Load(object sender, EventArgs e)
{
txtbx_LRU.Text = Form1.gelenveri2;
txtbx_kisiler.Text = Form1.gelenveri;
txtbx_parcano.Text = Form1.gelenveri3;
txtbx_bolum.Text=Form1.gelenveri_bolum;
txtbx_mod.Text = Form1.gelenveri_mod;
string path1 = @"C:\svn\DSBCA_PROGRAM\" + txtbx_bolum.Text
+ "\\" + txtbx_mod.Text + "\\" + txtbx_LRU.Text
+ "\\" + txtbx_parcano.Text;
// All the files/folders in the path1 will be
// transferred into the array filePaths.
string[] filePaths = Directory.GetFileSystemEntries(path1);
// Then we will get the number of how many items
// are in the string array
int boyut_dosya = filePaths.Length;
// this loop will go through the array
for (int i = 0; i < boyut_dosya; i++)
{
// the slashes in the path will be ignored here
string[] words = filePaths[i].Split('\\');
// How many folders(words) were opened
int k = words.Length;
// this will get the last file from the path(our desired file)
lstbx_sonuclar.Items.Add(words[k - 1]);
// just so we dont over load we set the array words to zero.
words = null;
//and k to zero too
k = 0;
}
}
private void lstbx_sonuclar_MouseDoubleClick(object sender, MouseEventArgs e)
{
//list box where the results will be displayed
string a = path1 + "\\" + lstbx_sonuclar.SelectedItem.ToString();
Process.Start(a);
}
Upvotes: 1
Views: 66
Reputation: 1287
In Form2_Load
you have created a local variable with the same name. it hides the class member.
Upvotes: 3