Re: Implementation Data Controls in asp.net hi, try this code
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
GetAttachmentInfo()
If Not Page.IsPostBack Then
GetData()
End If
End Sub
Sub GetAttachmentInfo()
Dim connString As String
Dim con As SqlConnection
Try
connString = System.Web.Configuration.WebConfigurationManager.C onnectionStrings("ConnectionString1").ConnectionSt ring
con = New SqlConnection(connString)
Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = con
cmd.CommandText = "dbo.GetAttachmentInfo"
cmd.CommandType = CommandType.StoredProcedure
Dim adapter As New SqlDataAdapter(cmd)
Dim attachments As New DataSet
adapter.Fill(attachments, "Attachments")
Dim i
Dim fileURL As String
For i = 0 To attachments.Tables(0).Rows.Count - 1
Dim dr As DataRow
dr = attachments.Tables(0).Rows(i)
Dim fileName = dr.Item("FileName").ToString
If [String].IsNullOrEmpty(fileName) = False Then
'Get the physical path to the file.
fileURL = Request.ApplicationPath.ToString & "/securesite/upload/" & fileName
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName)
Response.ContentType = "Application/octet-stream" 'pdf"
'Write the file directly to the HTTP content output stream.
Response.WriteFile(fileURL)
Response.End()
End If
Next i
Try
con.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex)
Finally
con.Close()
con.Dispose()
End Try
Catch ex As ApplicationException
Response.Write("Could not load the database")
End Try
End Sub
try thi |