Why is the file being corrupted (using a download tracker)?

S

Showjumper

I set up a download tracker. When i first tested it, all was fine. However
as i just found out via an email, the zip file is corrupt. Folks can
download the file but it just cant be opened. The download code appears to
work fine as far as logging the user and sending the file (as far as i can
tell) but my guess is that there is a problem with the download tracker that
is corrupt ing the file because the file is fine onmy local drive. Any
ideas?
Thanks,
Ashok
Code posted below.
Sub DownloadFile(ByVal forceDownload As Boolean)

Dim productcode As String =
HttpContext.Current.Request.QueryString("ProductCode").ToString

Dim productpath As String

Dim ds As DataSet = dal.ExecuteDataset(dal.RDConn, CommandType.Text, "Select
* From Products Where ProductCode=@ProductCode", "Products", New
OleDb.OleDbParameter("@ProductCode", productcode))

Dim fp As String = ds.Tables(0).Rows(0).Item("ProductPath").ToString

Dim name As String = Path.GetFileName(fp)

Dim ext As String = Path.GetExtension(fp)

dal.ExecuteNonQuery(dal.RDConn, CommandType.Text, "Update Products Set
ProductDownloadCount=ProductDownloadCount + 1 Where
ProductCode=@ProductCode", New OleDbParameter("@ProductCode",
productcode.ToString))





dal.ExecuteNonQuery(dal.RDConn, CommandType.Text, "Insert Into
ProductDLCount (ProductName, ProductCode,DateDownloaded, IPAddress) Values
(@ProductName, @ProductCode, @Date, @IPAddress)", New
OleDbParameter("@ProductName", name.ToString), New
OleDbParameter("@ProductCode", productcode), New OleDbParameter("@Date",
DateTime.Now.ToString("F")), New OleDbParameter(" @IPAddress",
HttpContext.Current.Request.UserHostAddress.ToString))

Dim type As String = ""

' set known types based on file extension

If Not (ext Is Nothing) Then

Select Case ext.ToLower()

Case ".htm", ".html"

HttpContext.Current.Response.ContentType = "text/HTML"

Case ".txt"

HttpContext.Current.Response.ContentType = "text/plain"

Case ".doc", ".rtf"

HttpContext.Current.Response.ContentType = "application/msword"

Case ".zip"

HttpContext.Current.Response.ContentType = "application/zip"

Case ""

HttpContext.Current.Response.ContentType = "application/octet-stream"

End Select

End If

If forceDownload Then

HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment; filename=" + name)

End If

If type <> "" Then

HttpContext.Current.Response.ContentType = type

End If

HttpContext.Current.Response.WriteFile(fp)

HttpContext.Current.Response.End()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top