R
Radu
Hi. I have the following problem: The user needs to setup a request on
a website, by deciding on a lot of questions. I want the website to
dump an excel (CSV) file into a shared folder somewhere on the
network, so that other tools can read these request files and act on
them.
So on my confirmation page I have a "PREVIOUS" and a "NEXT" button. On
the NEXT I currently have code which does many things (fills SQL
Server tables, sends confirmation emails, etc). I want to add some
more code which would export this request, as described above.
At some point, after I determine strNewFileName which would be like
"H:\PEOPLE\EPS\EPS 2nd version\RequestZZZ.xls"
I call:
Call ExportToExcel(strNewFileName)
where
Private Function ExportToExcel(ByVal strFileName As String) As Boolean
Dim stringWrite As System.IO.StringWriter = New
System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New
HtmlTextWriter(stringWrite)
Try
Response.Clear()
Response.AddHeader("content-disposition", "inline;filename='" &
strFileName & "'")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
'Get the HTML for the control:
dataGridSettingsLocations.RenderControl(htmlWrite)
'Write the HTML back to the browser:
Response.Write(stringWrite.ToString())
Response.End()
Catch ex As Exception
Throw ex
Finally
stringWrite.Dispose()
stringWrite = Nothing
htmlWrite.Dispose()
htmlWrite = Nothing
End Try
End Function
and after this call, I continue with other function calls, and in the
end, last line for cmdNext_Click, I say:
'I use this overloaded form because otherwise I get a
ThreadAbortException error - see article http://support.microsoft.com/kb/312629
Response.Redirect("Acknowledgement.aspx", False)
I have a number of problems:
1. If I use
Response.End()
in ExportToExcel, I get a 'thread ended' error - logical enough, I
think.
2. If I don't use it, the code above doesn't give me errors, but does
not save my file anywhere either...
3. Anyway, I'm not sure, with my VERY LIMITED ASP knowledge, that for
saving on the server and not on the client I should write code in
"RESPONSE", as you can see above. If not, how could I do what I have
to do ?
I would appreciate very much any answer - I have lost too much time on
this one already.
Thank you.
Alex.
a website, by deciding on a lot of questions. I want the website to
dump an excel (CSV) file into a shared folder somewhere on the
network, so that other tools can read these request files and act on
them.
So on my confirmation page I have a "PREVIOUS" and a "NEXT" button. On
the NEXT I currently have code which does many things (fills SQL
Server tables, sends confirmation emails, etc). I want to add some
more code which would export this request, as described above.
At some point, after I determine strNewFileName which would be like
"H:\PEOPLE\EPS\EPS 2nd version\RequestZZZ.xls"
I call:
Call ExportToExcel(strNewFileName)
where
Private Function ExportToExcel(ByVal strFileName As String) As Boolean
Dim stringWrite As System.IO.StringWriter = New
System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New
HtmlTextWriter(stringWrite)
Try
Response.Clear()
Response.AddHeader("content-disposition", "inline;filename='" &
strFileName & "'")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
'Get the HTML for the control:
dataGridSettingsLocations.RenderControl(htmlWrite)
'Write the HTML back to the browser:
Response.Write(stringWrite.ToString())
Response.End()
Catch ex As Exception
Throw ex
Finally
stringWrite.Dispose()
stringWrite = Nothing
htmlWrite.Dispose()
htmlWrite = Nothing
End Try
End Function
and after this call, I continue with other function calls, and in the
end, last line for cmdNext_Click, I say:
'I use this overloaded form because otherwise I get a
ThreadAbortException error - see article http://support.microsoft.com/kb/312629
Response.Redirect("Acknowledgement.aspx", False)
I have a number of problems:
1. If I use
Response.End()
in ExportToExcel, I get a 'thread ended' error - logical enough, I
think.
2. If I don't use it, the code above doesn't give me errors, but does
not save my file anywhere either...
3. Anyway, I'm not sure, with my VERY LIMITED ASP knowledge, that for
saving on the server and not on the client I should write code in
"RESPONSE", as you can see above. If not, how could I do what I have
to do ?
I would appreciate very much any answer - I have lost too much time on
this one already.
Thank you.
Alex.