Last post Aug 10, 2010 01:44 AM by worldspawn
Aug 08, 2010 03:54 PM|mohammad fares|LINK
i am doing a page to sell files online
the paying method is by a card or bank account and the customer is not registered to the site so i want to make sure that the customer has downloaded the file successfully after that the system completes the payment operation
so if there is any way to know do that tell me please
i use c# thanx all
Aug 08, 2010 06:49 PM|worldspawn|LINK
I'm not sure how you are serving the file. But you are manually streaming the file to the client then you should know it's done when you've got to the end of the file.
Just keep checking Response.IsClientConnected at the top of your while loop (not shown in the example).
That said you can't really know 100% for sure that they've received the file with no issues.
I dont have a sample handy of streaming a file from disk but I have this snippet, streaming from Amazon S3. Almost the same concept.
var stream = amazon.GetObjectStream(bucketName, fileName, out contentLength, out contentType);
//The content type returned is useless, usually octet-stream.
MemoryStream ms = new MemoryStream();
string mimeType = null;
byte buffer = new byte;
Response.AddHeader("Content-disposition", "attachment;filename=" + fileName);
long count = 0;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
count += bytesRead;
if (mimeType == null)
byte mimeBuffer = new byte;
if (bytesRead > mimeBuffer.Length)
Array.Copy(buffer, mimeBuffer, mimeBuffer.Length);
Array.Copy(buffer, mimeBuffer, bytesRead);
mimeType = MimeTypeUtil.CheckType(mimeBuffer);
Response.ContentType = mimeType;
Response.OutputStream.Write(buffer, 0, bytesRead);
The MIME checking stuff probably isn't something you will need. But if you do...
public class MimeTypeUtil
[DllImport(@"urlmon.dll", CharSet = CharSet.Auto)]
private extern static System.UInt32 FindMimeFromData(
[MarshalAs(UnmanagedType.LPStr)] System.String pwzUrl,
[MarshalAs(UnmanagedType.LPArray)] byte pBuffer,
[MarshalAs(UnmanagedType.LPStr)] System.String pwzMimeProposed,
out System.UInt32 ppwzMimeOut,
public static string CheckType(byte buffer)
System.UInt32 returnValue = FindMimeFromData(0, null, buffer, 256, null, 0, out mimeType, 0);
System.IntPtr mimeTypePointer = new IntPtr(mimeType);
catch (Exception ex)
Aug 09, 2010 11:20 AM|mohammad fares|LINK
thanx for the fast replay
but i couldn't understand what are all these vars for and where to but this code and what do yoy mean by serving file
the file is stored at same sever if that what you mean
still need help people
Aug 10, 2010 01:44 AM|worldspawn|LINK
Dont allow users to directly make request for the file. Have a http handler serve the request and manage the serving of the file data back to the browser. (which is basically the code i've given you).
Sorry this post is in httphandler and httpmodules so I assummed you had a httphandler serving you file... otherwise why is it here?
So map all requests to /files/*.* to ur handler (for example) and provide the file.