View Single Post
Join Date: Jul 2007
Posts: 276
Reputation: rapture has a spectacular aura about rapture has a spectacular aura about 
Solved Threads: 37
rapture rapture is offline Offline
Posting Whiz in Training

compare files in c#

 
0
  #1
Jul 29th, 2008
Hello,
I'm newer to programming and trying to do something that has me stumped. I need to read files from a directory on a server and compare those file names to a field in a database. When I find the file names that are the same, grab a different field which is actually a path to the server and see if the file exists there. If not, copy the file to that location. I've been working on this for quite some time, I have not started working on copying the files so I sort of want to try to figure that out on my own. But I need help in comparing the files, here is what I have so far...
  1.  
  2. namespace MissingImages
  3. {
  4. public partial class frmImages : Form
  5. {
  6. public frmImages()
  7. {
  8. InitializeComponent();
  9. }
  10.  
  11. private void btnGetDirFiles_Click(object sender, EventArgs e)
  12. {
  13.  
  14.  
  15.  
  16. DirectoryInfo dirCustom = new DirectoryInfo("\\\\disk2\\images\\Missing Images");
  17.  
  18. FileInfo[] filCustom;
  19.  
  20. filCustom = dirCustom.GetFiles();
  21.  
  22.  
  23.  
  24. }
  25.  
  26. private void btnOBJTable_Click(object sender, EventArgs e)
  27.  
  28. {
  29. SqlCommand cmd = new SqlCommand();
  30.  
  31. {
  32. frmImages rd = new frmImages();
  33. rd.SimpleRead();
  34. }
  35. }
  36.  
  37. public void SimpleRead()
  38. {
  39.  
  40. SqlDataReader rdr = null;
  41.  
  42. SqlConnection conn = new SqlConnection( "Server=TSQLTVS;UID=notreal;PWD=alsonotreal;Database=Flowtiva");
  43.  
  44. SqlCommand cmd = new SqlCommand("select FILENAME, SOID from obj", conn);
  45.  
  46. conn.Open();
  47.  
  48. rdr = cmd.ExecuteReader();
  49.  
  50.  
  51.  
  52. }
  53.  
  54.  
  55. }
  56. }

This does appear as I step through it to pull the information from both places. The SOID field in the obj table of the database is just a string with the server path in it.

Can anyone help or at least point me in the right direction?

Thanks in advance
Reply With Quote