Мы создаем поисковую систему, которая просматривает папки на компьютере и переносит поиск в окно списка, где вы можете открыть файлы и другие подпапки. Мы используем форму окна в С# для кода. У меня есть две формы окон, один (form1) получает запросы от пользователя, а вторая форма (form2) отображает результаты поиска. Проблема заключается в том, что в моем коде мои файлы и папки не могут быть найдены, потому что мой путь строки1 установлен в значение null, но я уже назначил это значение в форме 2. Если вы посмотрите на код, возможно, вы получите более четкое представление о том, что я подразумеваю под path1 и form2.My вопрос, как я могу это исправить? У моего друга такой же точный код, и он работает на нее но по какой-то причине мины имеют значение null, что мешает мне открывать файлы и папки.
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);
}
В Form2_Load
вы создали локальную переменную с тем же именем. он скрывает член класса.