Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,416 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,379 people online right now. Registration is fast and FREE... Join Now!




File searching

 
Reply to this topicStart new topic

File searching

divyapagidela
18 Aug, 2008 - 01:04 AM
Post #1

New D.I.C Head
*

Joined: 22 Jul, 2008
Posts: 15



Thanked: 1 times
My Contributions
Hiiiiiiiiii
I want the code for searching a file through all directories.........
I have some code with me
Plz tell me where I'm getting wrong
thanx in advance

User is offlineProfile CardPM
+Quote Post

dineeshd
RE: File Searching
18 Aug, 2008 - 01:09 AM
Post #2

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 578



Thanked: 16 times
Dream Kudos: 575
My Contributions
To tell what you are doing wrong, we need to see the code. So please post the code you have so far.
User is offlineProfile CardPM
+Quote Post

divyapagidela
RE: File Searching
18 Aug, 2008 - 01:50 AM
Post #3

New D.I.C Head
*

Joined: 22 Jul, 2008
Posts: 15



Thanked: 1 times
My Contributions
QUOTE(dineeshd @ 18 Aug, 2008 - 02:09 AM) *

To tell what you are doing wrong, we need to see the code. So please post the code you have so far.


my code is

csharp

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Media;


namespace search
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{


listBox1.Items.AddRange(Directory.GetFiles("F:\myprojects","*.txt","SearchOption.AllDirectories"));




}


}
}


now tell me the way to search a file
User is offlineProfile CardPM
+Quote Post

Korupt
RE: File Searching
18 Aug, 2008 - 10:49 AM
Post #4

D.I.C Head
Group Icon

Joined: 22 Jun, 2008
Posts: 58



Thanked: 1 times
Dream Kudos: 25
My Contributions
you need to add a Open File Dialog to your project and put this in your button:

csharp

openFileDialog1.ShowDialog();
listBox1.Items.Add(openFileDialog.FileName);

User is offlineProfile CardPM
+Quote Post

divyapagidela
RE: File Searching
18 Aug, 2008 - 11:02 PM
Post #5

New D.I.C Head
*

Joined: 22 Jul, 2008
Posts: 15



Thanked: 1 times
My Contributions
QUOTE(Korupt @ 18 Aug, 2008 - 11:49 AM) *

you need to add a Open File Dialog to your project and put this in your button:

csharp

openFileDialog1.ShowDialog();
listBox1.Items.Add(openFileDialog.FileName);




Thanx for ur reply

User is offlineProfile CardPM
+Quote Post

divyapagidela
RE: File Searching
18 Aug, 2008 - 11:16 PM
Post #6

New D.I.C Head
*

Joined: 22 Jul, 2008
Posts: 15



Thanked: 1 times
My Contributions
Hiiiiiiiiiiiiiiiiiii
In my project, I need code to list all subdirectories that are present in a specified main directory
I have some code with me
Plz check it out n tell me where I'm getting wrong and what steps I have to take n where
My code is:

csharp

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace search
{
public partial class Form1 : Form
{
string path;
string str;
string[] folders;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

folders = System.IO.Directory.GetDirectories(@"C:\", "*.txt", System.IO.SearchOption.AllDirectories);


}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{


textBox1.Text = listBox1.SelectedItem.ToString();


}

private void button2_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
path=saveFileDialog1.FileName + ".txt";
System.IO.File.AppendAllText(path, textBox2.Text);
MessageBox.Show("File Saved.....", "Success");

}

private void button3_Click(object sender, EventArgs e)
{
str = System.IO.File.ReadAllText(textBox1.Text);
textBox2.Text = str;

}

private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}


}
}




Thanx in advance smile.gif smile.gif smile.gif

** Edit ** code.gif

Also, please don't start duplicate topics of the same content. Topics merged.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:54PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month