Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Datagrid RenderControl to Excel. Problems

Datagrid RenderControl to Excel. Problems

Scheduled Pinned Locked Moved ASP.NET
designhelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Regardt
    wrote on last edited by
    #1

    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"--

    M J 2 Replies Last reply
    0
    • R Regardt

      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"--

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      0
      • M minhpc_bk

        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.

        R Offline
        R Offline
        Regardt
        wrote on last edited by
        #3

        Thanks for the reply I have try that already without any success. Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

        M 1 Reply Last reply
        0
        • R Regardt

          Thanks for the reply I have try that already without any success. Africa is a tough country --"Hello daar vir die Afrikaans sprekende"--

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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[^]

          R 1 Reply Last reply
          0
          • R Regardt

            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"--

            J Offline
            J Offline
            Jose Rojas
            wrote on last edited by
            #5

            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

            R 1 Reply Last reply
            0
            • J Jose Rojas

              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

              R Offline
              R Offline
              Regardt
              wrote on last edited by
              #6

              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"--

              1 Reply Last reply
              0
              • M minhpc_bk

                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[^]

                R Offline
                R Offline
                Regardt
                wrote on last edited by
                #7

                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"--

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups