0

**Hello guys,i'm new in C# and i don't know how to do the following code

I need to make a code that verifies 30 files from the server (URL) and 30 files from the client(folder)

and then compare them byte by byte,if the client(folder) files are altered/changed/deleted then download the server ones...that's all...could you help me with that?i used this code but didn't work...URI not supported error**

My code is here : http://codeupload.com/6192

If you have any other good idea that might help me please post it here

Catalin Mihai
  • 107
  • 1
  • 1
  • 6
  • What error are you getting, specifically? URI formats are not supported? Put a breakpoint in your code, and see what URL you are passing around; my guess is it doesn't look like you think it does. – Patrick Pitre Jul 17 '12 at 21:35

2 Answers2

0

To compare them byte by byte you already have to download the object. If you wan't to compare them without downloading the file from the server, you have to use a server-side script. For example create a simple php script that creates the MD5 hashes for a file (filename provided in the url), download the MD5 file and compare it to the MD5 hash of the local file. If they differ download the real file.

teamalpha5441
  • 741
  • 1
  • 6
  • 20
0

You should download each file using WebClient.DownloadData method (http://msdn.microsoft.com/en-us/library/ms144188.aspx).

then you will get a byte array that you will have to compare with your local file byte array (use File.ReadAllBytes() - http://msdn.microsoft.com/en-us/library/system.io.file.readallbytes.aspx)

eyossi
  • 4,230
  • 22
  • 20
  • Can't i use other methods? or it's the only one? – Catalin Mihai Jul 17 '12 at 21:53
  • You can use other methods, but i don't think you can use other methods that will make you have less code... so those are the methods i would suggest you to use (and in other words - don't use streams... i don't think you need it in your case) – eyossi Jul 17 '12 at 21:54
  • Hmm could you make me a fast code that copies the file to the temp folder then check if file bytes are equal to the one in the folder ,then if the files from the folder are altered copy the one from the temp folder to files folder , if not delete the files from temp folder – Catalin Mihai Jul 17 '12 at 21:56
  • Or atleast give me an idea how to get all the files from the folder...the format is file_01,file_02....file_10,file_11...file_30 – Catalin Mihai Jul 17 '12 at 22:00
  • Getting files from a directory - `Directory.GetFiles()` (http://msdn.microsoft.com/en-us/library/07wt70x2.aspx) – eyossi Jul 17 '12 at 22:02
  • You have any idea why my code can't create a file on C:/Windows/Temp folder? WebClient webClient = new WebClient(); webClient.DownloadFileAsync(new Uri("http://127.0.0.1/maps/test.mcl"), @"C:/test.mcl"); – Catalin Mihai Jul 17 '12 at 23:08