Hi to all,
I want to downlaod a execl file and than fetch it.
i try it-
Sub DownloadFile()
Try
Dim dsExport As New DataSet
Dim tw As New StringWriter
Dim hw As New Html32TextWriter(tw)
Dim dgGrid As New DataGrid
Dim arrparam(0) As SqlParameter
arrparam(0) = New SqlParameter("@Yr_Code",
helper.Get_Year_Code())
dsExport = dbl.GetDataSetProc("sp_sel_books_delivered_LandMark",
arrparam)
dgGrid.DataSource = dsExport
'REPORT Header
'hw.WriteLine("<b><u><font size='4'>Book Delivered
List</font></u></b>")
'Get the HTML for the control.
Dim objfont As New FontUnit
'dgGrid.HeaderStyle.Font.Bold = True
'dgGrid.HeaderStyle.Font.Size = objfont.Point(12)
'dgGrid.ItemStyle.Font.Name = "Verdana"
'dgGrid.ItemStyle.Font.Size = objfont.Point(8)
'dgGrid.AlternatingItemStyle.Font.Name = "Verdana"
'dgGrid.AlternatingItemStyle.Font.Size = objfont.Point(8)
dgGrid.DataBind()
dgGrid.RenderControl(hw)
' Write the HTML back to the browser.
Response.ContentType = "application/vnd.ms-excel"
'code to add the filename to the contents
Response.AppendHeader("Content-Disposition",
"filename=BooksDeliveredReport.xls")
Page.EnableViewState = False
Response.Write(tw.ToString())
Response.End()
Catch ex As Exception
' MessageBox.Show(ex.Message)
End Try
End Sub
and fetch it
lblTotAdded.InnerText = " "
strPath = Server.MapPath("")
strPath = strPath & "\temp\"
Dim strFile As String = Me.PortFile.PostedFile.FileName
strFile = strFile.Substring(strFile.LastIndexOf("\") + 1)
strPath = strPath & strFile
viewstate.Add("FullPath", strPath)
Me.PortFile.PostedFile.SaveAs(viewstate("FullPath"))
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & viewstate("FullPath") & ";Extended Properties=""Excel
8.0;HDR=YES;"""
viewstate.Add("conString", strConn)
Dim CN As OleDbConnection
CN = New OleDbConnection(strConn)
CN.Open()
Dim dt As New DataTable
dt =
CN.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing,
Nothing, "TABLE"})
Me.ddlSheets.DataSource = dt
Me.ddlSheets.DataTextField = "TABLE_NAME"
Me.ddlSheets.DataBind()
CN.Close()
CN = Nothing
'Validating the file types
Dim strFileName As String
Dim index As Integer
Dim len As Integer
strFileName = PortFile.PostedFile.FileName
index = strFileName.LastIndexOfAny("\") + 1
len = strFileName.Length - 4
strFileName = strFileName.Substring(index)
strFileName = strFileName.Substring(0,
strFileName.LastIndexOfAny("."))
strFileName = strFileName.ToLower
but i hav a problem if i simple download n fetch thn it give error. but if i
copy this excel into another thn it working.
plz help out.
thanx in advance