1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

so very stuck

Discussion in 'C#' started by becky007, Aug 28, 2010.

  1. becky007

    becky007 New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hey guys. i get an error "Could not find a part of the path" for inputStream = File.OpenText(textBox1.Text).
    The idea is to enter a folders path then in another textbox enter word to search.
    all the files in the folder have to be searched then the word,filename and path are strung into texbox2.
    any ideas at what to do || what im doing wrong? Thanks heaps


    private void searchbutton_Click(object sender, EventArgs e)
    {
    String Word;
    string[] words = new string[3];
    char []seperator = {','};
    bool found = false;
    StreamReader inputStream;
    if (inputtextBox.Text == "")
    {
    MessageBox.Show("Please enter something to search in files", "Error");
    inputtextBox.Focus();
    }
    else
    try
    {
    string[] directories = Directory.GetDirectories(textBox1.Text);
    string[] files = Directory.GetFiles(textBox1.Text);
    inputStream = File.OpenText(textBox1.Text);//* error comes in here*\\

    Word = inputStream.ReadLine();

    while ((Word != null) && found == false)
    {
    words = Word.Split(seperator);
    if (words[0].Trim() == inputtextBox.Text)
    {
    textBox2.Text = words[1].Trim();
    textBox2.Text = words[2].Trim();
    found = true;
    }
    }
    inputStream.Close();

    for (int i = 0; i < files.Length; i++)
    {
    if (files.Contains(inputtextBox.Text))
    textBox2.Text += files.Substring(files.LastIndexOf('\\') + 1) + "\t" + files + "\n";
    }
     

Share This Page