Datagrid RenderControl to Excel. Problems
-
Hi all, The rendercontrol works prefectly, but in certain page I receive a error message in Excel informing me that the excel file can not be found. Any ideas? Thanks Regardt PS. Excample of the code With m_Page .Response.Clear() .Response.AddHeader("Content Disposition", "attachment;filename=" & Title & ".xls") .Response.Buffer = True .Response.ContentType = "application/vnd.ms-excel" .Response.ContentEncoding = System.Text.Encoding.UTF7 .Response.Charset = "" m_Grid.EnableViewState = False Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) ClearControls(m_Grid) FrontDecorator(oHtmlTextWriter) m_Grid.RenderControl(oHtmlTextWriter) RearDecorator(oHtmlTextWriter) .Response.Write(oStringWriter.ToString()) .Response.End() End With Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--
-
Hi all, The rendercontrol works prefectly, but in certain page I receive a error message in Excel informing me that the excel file can not be found. Any ideas? Thanks Regardt PS. Excample of the code With m_Page .Response.Clear() .Response.AddHeader("Content Disposition", "attachment;filename=" & Title & ".xls") .Response.Buffer = True .Response.ContentType = "application/vnd.ms-excel" .Response.ContentEncoding = System.Text.Encoding.UTF7 .Response.Charset = "" m_Grid.EnableViewState = False Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) ClearControls(m_Grid) FrontDecorator(oHtmlTextWriter) m_Grid.RenderControl(oHtmlTextWriter) RearDecorator(oHtmlTextWriter) .Response.Write(oStringWriter.ToString()) .Response.End() End With Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--
Hi there, In certain pages where you get that error, you can try to re-check the Title value which is used to suggest a filename for the xls file to see if the filename is valid or contains any space in there. The filename with spaces sometimes causes this kind of errors.
-
Hi there, In certain pages where you get that error, you can try to re-check the Title value which is used to suggest a filename for the xls file to see if the filename is valid or contains any space in there. The filename with spaces sometimes causes this kind of errors.
-
Thanks for the reply I have try that already without any success. Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--
Hi there, If the filename is not the case, I might think of the fact that the file was corrupted somehow such as the contents are altered in the wrong way ..., but instead of giving a sensible error message, Excel provided a message saying something like "file could not be found..." which really does not help much. Btw, do you need to encode the contents with UTF7? I tried with the example in this document a of couple of times without getting any error. http://support.microsoft.com/kb/317719[^]
-
Hi all, The rendercontrol works prefectly, but in certain page I receive a error message in Excel informing me that the excel file can not be found. Any ideas? Thanks Regardt PS. Excample of the code With m_Page .Response.Clear() .Response.AddHeader("Content Disposition", "attachment;filename=" & Title & ".xls") .Response.Buffer = True .Response.ContentType = "application/vnd.ms-excel" .Response.ContentEncoding = System.Text.Encoding.UTF7 .Response.Charset = "" m_Grid.EnableViewState = False Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter) ClearControls(m_Grid) FrontDecorator(oHtmlTextWriter) m_Grid.RenderControl(oHtmlTextWriter) RearDecorator(oHtmlTextWriter) .Response.Write(oStringWriter.ToString()) .Response.End() End With Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--
I am trying to send data to excel but I keep getting this error, must be placed inside a form tag with runat=server. I see that you have a function that its call ClearControls(m_grid) can you please help me on this one. Thanks
-
I am trying to send data to excel but I keep getting this error, must be placed inside a form tag with runat=server. I see that you have a function that its call ClearControls(m_grid) can you please help me on this one. Thanks
Hope the clear control methode will help. Private Sub ClearControls(ByRef Control As Control) Dim i As Integer 'recursively call this procedure to clear nested controls For i = Control.Controls.Count - 1 To 0 Step -1 ClearControls(Control.Controls(i)) Next Try If Not TypeOf Control Is System.Web.UI.WebControls.DataGrid Then If Not TypeOf Control Is System.Web.UI.WebControls.TableCell Then If Not Control.GetType().GetProperty("SelectedItem") Is Nothing Then Dim Literal As New LiteralControl Try Control.Parent.Controls.Add(Literal) Literal.Text = Convert.ToString(Control.GetType.GetProperty("SelectedItem").GetValue(Control, Nothing)) Catch ex As Exception Throw ex Finally Control.Parent.Controls.Remove(Control) End Try Else If Not Control.GetType().GetProperty("Text") Is Nothing Then Dim literal = New LiteralControl Control.Parent.Controls.Add(literal) literal.Text = Convert.ToString(Control.GetType().GetProperty("Text").GetValue(Control, Nothing)) Control.Parent.Controls.Remove(Control) End If End If End If End If Catch ex As Exception Throw ex End Try End Sub Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--
-
Hi there, If the filename is not the case, I might think of the fact that the file was corrupted somehow such as the contents are altered in the wrong way ..., but instead of giving a sensible error message, Excel provided a message saying something like "file could not be found..." which really does not help much. Btw, do you need to encode the contents with UTF7? I tried with the example in this document a of couple of times without getting any error. http://support.microsoft.com/kb/317719[^]
Thanks for the support, but I have decided to leave this problem for the future. (To much work) Just a summary of the state of the problem for future developers with the same type of problem. The rendering always work, if excel is already opened. The option to save the excel file to your PC also work and the file opens with out any problems. The rendering problem only occurs in some instances, without any sufficient changes on the structure /data of the datagrid or table, when trying to open the excel file on request. Cheers Regardt Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--