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

Re: compare files in c#

 
0
  #7
Aug 8th, 2008
Thanks again for the help - I have successfully been able to do the compare - although it beat me up pretty good.

I wanted to post the code that I was able to get to work for the compare feature in case anyone else was looking (It's not pretty but works)

Now all I have to do is take the filename and change the name to the last part of the file path. (ie 00033569.TIF to 00001695) then I need to copy the file out to the file path.

I suppose I ought to back up the data first before changing the information so I don't lose it in case something breaks.


  1. List<string> SOIDs;
  2. List<string> filesInDatabase = GetDatabaseFileName(out SOIDs);
  3. List<string> filesOnServer = GetServerFileNames();
  4.  
  5. foreach ( string fileName in filesOnServer )
  6.  
  7. {
  8. string fileOnly = Path.GetFileNameWithoutExtension(fileName).ToString();
  9.  
  10. if ( filesInDatabase.Contains(fileOnly) )
  11. {
  12.  
  13. int index = filesInDatabase.IndexOf(fileOnly);
  14. if (index >= 0)
  15. {
  16. if ( !File.Exists(SOIDs[index]) )
  17. {
  18.  
  19.  
  20. txtFiles.AppendText(fileOnly + " " + SOIDs[index] + "\r\n");
  21.  
  22.  
  23. }
  24. }
  25. }
  26. }
  27.  
  28. }
  29.  
  30. protected static List<string> GetDatabaseFileName( out List<string> SOID)
  31. {
  32. List<string> returnValue = new List<string>();
  33. SOID = new List<string>();
  34. using ( SqlConnection connection = new SqlConnection(@"Server=TSQLTVS;UID=*****;PWD=**********;Database=Flowtiva"))
  35. {
  36. connection.Open();
  37.  
  38.  
  39. using ( SqlCommand command = connection.CreateCommand() )
  40. {
  41. command.CommandType = CommandType.Text;
  42. command.CommandText = @"SQL query here";
  43.  
  44. using ( SqlDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection) )
  45. {
  46. while ( dataReader.Read() )
  47. {
  48. returnValue.Add(dataReader.GetString(0));
  49.  
  50. SOID.Add(dataReader.GetString(1));
  51. }
  52. }
  53. }
  54.  
  55. }
  56.  
  57. return returnValue;
  58. }
  59.  
  60. protected static List<string> GetServerFileNames()
  61. {
  62. List<string> returnValue = new List<string>();
  63.  
  64. if (Directory.Exists("\\\\disk2\\images\\Missing Images"))
  65. {
  66. string[] files = Directory.GetFiles("\\\\disk2\\images\\Missing Images");
  67.  
  68. returnValue.AddRange(files);
  69.  
  70. }
  71. return returnValue;
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78. }
Reply With Quote