cvboucher
Posts: 191
|
Posted: 10/25/2009, 9:49 PM |
|
I figured out how to do this. There may be a better way but this works in case anyone else is trying to accomplish the same thing.
First I create a procedure to assign the primary key value as a command argument to the button.
Private Sub IS_TemplatePages_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles IS_TemplatePages.ItemDataBound
If e.Item.ItemType = ListItemType.Item Then
Dim row As DataRowView = e.Item.DataItem
Dim btnPreview As Button = e.Item.FindControl("btnPreview")
btnPreview.CommandName = "Preview"
btnPreview.CommandArgument = row("TemplatePageID").ToString()
End If
End Sub
Then I added another procedure to perform my code when the Preview Button is clicked.
Private Sub IS_TemplatePages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles IS_TemplatePages.ItemCommand
If e.CommandName = "Preview" Then
Dim path As String = ConfigurationManager.AppSettings("ServerPath") + "/innersight_template_pages/" + e.CommandArgument + ".pdf.resources"
Dim file As New System.IO.FileInfo(path)
Dim fn As String = System.IO.Path.GetFileName(path)
If (file.Exists) Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" + fn.Replace(".resources", ""))
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/pdf"
Response.WriteFile(file.FullName)
Response.End()
Else
IS_TemplatePages.Errors.Add("This file you requested, " + fn + ", does not exist.")
End If
End If
End Sub
Both of these procedures where just inserted between other procedures. I didn't use any object events to place the code.
Now I have another question but I'll post that in another thread.
Thanks,
Craig
|