Chris . . . I looked at some of my old code when I was trying to get this to work . . .
Code:
Sub btnDownload_Click(Sender As Object, E As EventArgs)
if page.IsValid
Response.ContentType = "application/zip"
Response.AppendHeader("Content-Disposition","attachment; filename=MySaveAsFile.zip")
Response.TransmitFile( server.mappath("MyPath/MyFile.zip") )
Response.End
end if
End Sub
This did not work as we would expect. Although the file transmitted flawlessly, response.end terminates any further code execution. and there is more code in the current sub to update the databases that the file was indeed downloaded. I even tried:
Code:
Server.Execute("MyPath/MyFile.zip")
What I have now is as follows:
Code:
Sub btnDownload_Click(Sender As Object, E As EventArgs)
if page.IsValid
' First get the purchase data (This should have already been done)
getPurchaseData()
' Serve the file - will auto rename to the page name with ".zip"
if vPurchasedFile = "Chrome SL v1.0 Donation" then Server.Execute("MyPath/MyFile.zip")
if vPurchasedFile = "Chrome v2.0 Donation" then Server.Execute("MyPath/MyFile.zip")
' increment the downloads
vNumberDownloads = vNumberDownloads + 1
' update the Purchase database with the total number of downloads
' strSQL = "UPDATE [Purchased] SET [Downloads]='" & vNumberDownloads & "' and [EULA] = "true" WHERE tGUID='" & session("vGUID") & "'"
strSQL = "(UPDATE [Purchased] SET [Downloads] = @NumDownloads, [EULA] = @EULADone WHERE [tGUID] = @vGUID)"
dbCommand = New OleDbCommand(strSQL, objConnection)
dbCommand.Parameters.AddWithValue("@NumDownloads", vNumberDownloads)
dbCommand.Parameters.AddWithValue("@EULADone", "1")
dbCommand.Parameters.AddWithValue("@vGUID", session("vGUID"))
Try
objConnection.Open()
dbCommand.ExecuteNonQuery()
Catch ex As Exception
Response.Write("<h2 class=""b_maroon"">" & ex.Message & "</h2>")
Response.End
Finally
If objConnection.State = ConnectionState.Open Then objConnection.Close()
End Try
' Response.Write("<h2 class=""b_orange"">A purchase record has been updated!!</h2>")
' Create the NEW download completed record and insert into the database
strSQL = "INSERT INTO Downloads (tGUID, dDate, dIP) VALUES (@tGUID, @dDate, @dIP)"
dbCommand = New OleDbCommand(strSQL, objConnection)
dbCommand.Parameters.AddWithValue("@tGUID", session("vGUID"))
dbCommand.Parameters.AddWithValue("@dDate", DateTime.Now.ToString())
dbCommand.Parameters.AddWithValue("@pIP", UserIPAddress)
Try
objConnection.Open()
dbCommand.ExecuteNonQuery()
Catch ex As Exception
Response.Write("<h2 class=""b_maroon"">" & ex.Message & "</h2>")
Response.End
Finally
If objConnection.State = ConnectionState.Open Then objConnection.Close()
End Try
' Response.Write("<h2 class=""b_orange"">A new download record has been added!!</h2>")
End If
End Sub
If you could shed some light on a better way of doing this I would love to hear it. I thought about using a popup but most browsers block the popups. The popup could be passed hidden parms to enable the down load and the db update code could still be run.
The page logic is as follows:
Is there a admin query present in the QueryString?
Then show admin data. Page Quit.
Else Is this a PayPal return (from purchase/donation)?
Then show finalize PayPal purchase/donation by
creating db records
generate email
show download button
Else Is this a return file download?
Then determine if download allowed (max days, max downloads)
if agreed to terms then precheck the terms box and show download button
Else show error
Else This MUST be a first visit
show first impression with donation buttons
There is also present a css and I have not moved this to code behind mainly becuase there is very little code - its mostly building the output which is displayed via response.write. I traditionally was an asp developer and asp.net is new to me over the past year. VB vs. VB.net really had a lot of little syntax changes that caused me great headaches . . . LOL
Bookmarks