problem when exporting datagrid to excel [modified]
-
Hi, I've seen people complain about this error other places, but noone ever answers them... Can't find solution to this erro message: 'c:\documents....\...xls' could not be found. Check the selling blah blah blah (it appears in excel when clicking the send to excel button) It seems it's trying to open a file that doesn't exist yet or something... Then I can click the button on my apsx page again, and it will work fine in excel... But any help solving this problem will be very appreciated... I'm sure some of you have seen this probelm before? :s -- modified at 4:20 Monday 7th August, 2006 the code: Response.Clear() Response.Buffer = True Response.AddHeader("Content-Disposition", "attachment;filename=Wells.xls") Response.ContentType = "application/vnd.ms-excel" Me.EnableViewState = False Response.Charset = String.Empty Dim myTextWriter As New System.IO.StringWriter() Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter) Exceldg.RenderControl(myHtmlTextWriter) Response.Write(myTextWriter.ToString()) Response.End() when i remove the line Response.AddHeader("Content-Disposition", "attachment;filename=Wells.xls") it just opens the excel inside the browser without errors, so i'm guessing error is from that line for some unknown (to me) reason
-
Hi, I've seen people complain about this error other places, but noone ever answers them... Can't find solution to this erro message: 'c:\documents....\...xls' could not be found. Check the selling blah blah blah (it appears in excel when clicking the send to excel button) It seems it's trying to open a file that doesn't exist yet or something... Then I can click the button on my apsx page again, and it will work fine in excel... But any help solving this problem will be very appreciated... I'm sure some of you have seen this probelm before? :s -- modified at 4:20 Monday 7th August, 2006 the code: Response.Clear() Response.Buffer = True Response.AddHeader("Content-Disposition", "attachment;filename=Wells.xls") Response.ContentType = "application/vnd.ms-excel" Me.EnableViewState = False Response.Charset = String.Empty Dim myTextWriter As New System.IO.StringWriter() Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter) Exceldg.RenderControl(myHtmlTextWriter) Response.Write(myTextWriter.ToString()) Response.End() when i remove the line Response.AddHeader("Content-Disposition", "attachment;filename=Wells.xls") it just opens the excel inside the browser without errors, so i'm guessing error is from that line for some unknown (to me) reason
Solved it myself, posting solution for others: I had and needed this on top of my page Response.CacheControl = "no-cache" (Or it wouldn't show last added items..) Had to remove that line to get the excel thing working... And to solve the display thing, I just sent a unique new id for each time a record was added (open aaa.aspx?id="& newID &" instead of open aaa.aspx))