I am migrating data into SharePoint Document Library using web service. Here i need to check whether folder/document already exists before creating and have to verify the data using checksum. I checked folder/document exists already using Lists.asmx. How to use checksum here??
1 Answer
You can create an eventHandler, calculating checksum. Code for checksum is below.
private string CalculateChecksum(string fileUrlString)
{
byte[] byteToCalculate = ReadAllBytes(fileUrlString);
int checksum = 0;
foreach (byte chData in byteToCalculate)
{
checksum += chData;
}
checksum &= 0xff;
return checksum.ToString("X2");
}
public static byte[] ReadAllBytes(string path)
{
byte[] bytes;
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
int index = 0;
long fileLength = fs.Length;
if (fileLength > Int32.MaxValue)
throw new IOException(“File too long”);
int count = (int)fileLength;
bytes = new byte[count];
while (count > 0)
{
int n = fs.Read(bytes, index, count);
if (n == 0)
throw new InvalidOperationException(“End of file reached before expected”);
index += n;
count -= n;
}
}
return bytes;
}