I want to retrive the file saved in the folder on my application using the file path from the database but i have not succeeded
please help
Public Class View
Inherits System.Web.UI.Page
Dim constr As String = ConfigurationManager.ConnectionStrings("OnlineShopConnectionString").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim strConnStringT As String = ConfigurationManager.ConnectionStrings("OnlineShopConnectionString").ConnectionString
Dim idd As String = Request.QueryString("idd").ToString()
Using con As SqlConnection = New SqlConnection(strConnStringT)
Using cmd As SqlCommand = New SqlCommand()
cmd.CommandText = "ITEM_SELECT_IID"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@IID", idd)
cmd.Connection = con
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
sdr.Read()
lblname.Text = sdr("iname").ToString()
lbldetil.Text = sdr("detail").ToString()
lblprice.Text = sdr("price").ToString()
lblqnt.Text = sdr("aqnt").ToString()
Image3.ImageUrl = sdr("image").ToString()
Image4.ImageUrl = sdr("image").ToString()
Image5.ImageUrl = sdr("image1").ToString()
Image6.ImageUrl = sdr("image2").ToString()
Image7.ImageUrl = sdr("image3").ToString()
con.Close()
End Using
End Using
End If
End Sub
Protected Sub bttnpdf_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim strConnStringT As String = ConfigurationManager.ConnectionStrings("OnlineShopConnectionString").ConnectionString
Dim Holdfile As String
Dim idd As String = Request.QueryString("idd").ToString()
Using con As SqlConnection = New SqlConnection(strConnStringT)
Using cmd As SqlCommand = New SqlCommand()
cmd.CommandText = "ITEM_SELECT_IIDFILE"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@IID", idd)
cmd.Connection = con
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
sdr.Read()
Holdfile = sdr("FilePath").ToString()
con.Close()
End Using
End Using
Dim FilePath As String = Holdfile
Dim User As New WebClient()
Dim FileBuffer As [Byte]() = User.DownloadData(FilePath)
If FileBuffer IsNot Nothing Then
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", FileBuffer.Length.ToString())
Response.BinaryWrite(FileBuffer)
End If
End Sub
End Class
Could not find file 'E:\Books\diving-into-Asp-Net-webapi.pdf'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not find file 'E:\Books\diving-into-Asp-Net-webapi.pdf'.
Source Error:
Line 68: Dim FilePath As String = Holdfile
Line 69: Dim User As New WebClient()
Line 70: Dim FileBuffer As [Byte]() = User.DownloadData(FilePath)
Line 71: If FileBuffer IsNot Nothing Then
Line 72: Response.ContentType = "application/pdf"