views:

22

answers:

1

Client is building a web based Digital Asset Management system. Here is the scenario: We have a large file, say 100 MB or more. Client needs to track both when a download of that file is requested (easy) and then if that download was successful. The large file takes a while to download, so almost needs some kind of callback of when that file completes downloading to a machine.

In IE, you have the Open/Save/Cancel dialog box. If you have Chrome/FF, it's a download manager. I'm not sure if there any events to tap into to find out if a file completes a download.

How would I do this without having some kind of ActiveX Control or Java applet that would report back if that file is successfully downloaded or not.

A: 

This blog post is the answer to this question. The trick is downloading this file in packets of 1024, then confirming the total count. I was able to use this logic with a SharePoint feature when downloading files from a document library. I update a custom list when successful or failure of that download.

http://www.codeproject.com/KB/aspnet/Download_Track.aspx

//Dividing the data in 1024 bytes package
int maxCount = (int)Math.Ceiling((FileName.Length - startBytes + 0.0) / 1024); 

//Download in block of 1024 bytes
int i;
for(i=0; i < maxCount && Response.IsClientConnected; i++)
{
    Response.BinaryWrite(_BinaryReader.ReadBytes(1024));
    Response.Flush(); 
}

Then we compare the number of data packets transferred with the total number of data packets which we calculated by dividing file length by 1024. If both the parameters are equal, that means that file transfer is successful and all the packets got transferred. If number of data packets transferred are less than the total number of data packets, that indicates there is some problem and the transfer was not complete.

//compare packets transferred with total number of packets
if (i < maxCount) return false;
return true;  
//Close the Binary reader and File stream in final block.


//Close Binary reader and File stream
_BinaryReader.Close();
myFile.Close(); 
Shane