Error in uploading an Excel file

Posted by Krishnasamy2008 under ASP.NET on 8/17/2011 | Points: 10 | Views : 1748 | Status : [Member] | Replies : 1
Hi Friends,

I'm using the uploadFile control to upload an excel file to server.The excel file getting while exporting the excel sheet.After that i have upload the exported excel file using asp.net file upload control.

Export to excel:
----------------
Private Sub ExportToExcel(ByVal dt As DataTable, ByVal response As HttpResponse, ByVal fileName As String)

'instantiate a Gridview
Dim grdView As New GridView
'create a string writer
Dim stringWrite As New System.IO.StringWriter
'create an htmltextwriter which uses the stringwriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Try
'first let's clean up the response.object
response.Clear()
response.Charset = ""
response.ClearHeaders()
response.Buffer = True
'set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
response.AddHeader("content-disposition", String.Format("attachment; filename={0}", fileName))
'set the gridview datasource to the dataset passed in
grdView.DataSource = dt
'bind the gridview
grdView.DataBind()
'Formating text for Bank Account field
Dim styleSheet As String = "<style>.text { mso-number-format:\@;}</style>"
response.Write(styleSheet)
Dim rowPosition As Integer
For rowPosition = 0 To dt.Rows.Count - 1
grdView.Rows(rowPosition).Cells(5).Attributes.Add("class", "text")
Next

'tell the gridview to render itself to our htmltextwriter
grdView.RenderControl(htmlWrite)
'all that's left is to output the html
response.Write(stringWrite.ToString)
'Sends all currently buffered output to the client
'response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
PageIsTerminating = True

Catch ex As Exception
Throw ex
Finally
grdView.Dispose()
'response.End()
End Try

End Sub

The file is not uploaded properly but i'm getting the following error:

{

Problem came up during following area during load.

Missing file: ..\Filename_files\sheet001.htm

}

Can anyone share your ideas.

Thanks,
krishna.K




Responses

Posted by: Bkarthik on: 8/18/2011 [Member] Starter | Points: 25

Up
0
Down
Hai krishna...

I think, the file name should be save with .xls or.xl file extension..
Please try for that.


all the best

Karthik Beeravelli

Krishnasamy2008, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response