Showing posts with label document. Show all posts
Showing posts with label document. Show all posts

Wednesday, March 28, 2012

There was an error generating the XML document.

Hello when I serialize an object an error generated using this function
public string SerializeObject(object oClassObject,System.Type oClassType)
{
XmlSerializer oSerializer = new XmlSerializer(oClassType);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
try
{
oSerializer.Serialize(writer,oClassObject);
}
catch(InvalidOperationException ex)
{
string msg = ex.Message;
string stack = ex.StackTrace;
}
return strBuilder.ToString();
}
and exception occured with message "There was an error generating the XML
document."
how can I know where is the error occured the stack trace did not give usef
info
StackTrace : " at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object
o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object
o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
oClassType) in d:\\scorm\\test\\form1.cs:line 133" string
line 133 where I called oSerializer.Serialize(writer,oClassObject);
Any Suggestions?And that's all the stack trace? There isn't anything more in the error
description (no description of inner exception whatsoever)?
I think you'd get replies faster by asking this at
microsoft.public.dotnet.xml group (I sent this to that group).
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
"Raed Sawalha" <RaedSawalha@.discussions.microsoft.com> wrote in message
news:050B90D9-6524-46CD-BB20-E1FE3BAE0367@.microsoft.com...
> Hello when I serialize an object an error generated using this function
> public string SerializeObject(object oClassObject,System.Type oClassType)
> {
> XmlSerializer oSerializer = new XmlSerializer(oClassType);
> System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
> System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
> try
> {
> oSerializer.Serialize(writer,oClassObject);
> }
> catch(InvalidOperationException ex)
> {
> string msg = ex.Message;
> string stack = ex.StackTrace;
> }
> return strBuilder.ToString();
> }
> and exception occured with message "There was an error generating the XML
> document."
> how can I know where is the error occured the stack trace did not give
> usef
> info
> StackTrace : " at
> System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
> Object
> o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
> Object
> o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
> Object o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
> Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
> oClassType) in d:\\scorm\\test\\form1.cs:line 133" string
> line 133 where I called oSerializer.Serialize(writer,oClassObject);
> Any Suggestions?
Can you post the definition of the class you're trying to serialize?
If the class is not serializable, the XmlSerializer is going to have a
hard time turning it into an XML document :)
Greetings,
Wessel
--Original Message--
From: Raed Sawalha [mailto:RaedSawalha@.discussions.microsoft.com]
Posted At: Sunday, April 10, 2005 11:25 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: There was an error generating the XML document.
Subject: There was an error generating the XML document.
Hello when I serialize an object an error generated using this function
public string SerializeObject(object oClassObject,System.Type
oClassType)
{
XmlSerializer oSerializer = new XmlSerializer(oClassType);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
try
{
oSerializer.Serialize(writer,oClassObject);
}
catch(InvalidOperationException ex)
{
string msg = ex.Message;
string stack = ex.StackTrace;
}
return strBuilder.ToString();
}
and exception occured with message "There was an error generating the
XML
document."
how can I know where is the error occured the stack trace did not give
usef
info
StackTrace : " at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object
o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object
o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter,
Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
oClassType) in d:\\scorm\\test\\form1.cs:line 133" string
line 133 where I called oSerializer.Serialize(writer,oClassObject);
Any Suggestions?
Hello Raed,
Your code looks ok. You'll need to dig down into the InnerException ... buri
ed
down in there you'll find the root cause of the problem.
Matt Berther
http://www.mattberther.com

> Hello when I serialize an object an error generated using this
> function
> public string SerializeObject(object oClassObject,System.Type
> oClassType)
> {
> XmlSerializer oSerializer = new XmlSerializer(oClassType);
> System.Text.StringBuilder strBuilder = new
> System.Text.StringBuilder();
> System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
> try
> {
> oSerializer.Serialize(writer,oClassObject);
> }
> catch(InvalidOperationException ex)
> {
> string msg = ex.Message;
> string stack = ex.StackTrace;
> }
> return strBuilder.ToString();
> }
> and exception occured with message "There was an error generating the
> XML
> document."
> how can I know where is the error occured the stack trace did not give
> usef
> info
> StackTrace : " at
> System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
> Object o, XmlSerializerNamespaces namespaces, String
> encodingStyle)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
> Object o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
> textWriter, Object o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
> textWriter, Object o)\r\n at Test.Form1.SerializeObject(Object
> oClassObject, Type oClassType) in d:\\scorm\\test\\form1.cs:line 133"
> string
> line 133 where I called oSerializer.Serialize(writer,oClassObject);
> Any Suggestions?
>

There was an error generating the XML document.

Hello when I serialize an object an error generated using this function
public string SerializeObject(object oClassObject,System.Type oClassType)
{
XmlSerializer oSerializer = new XmlSerializer(oClassType);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
try
{
oSerializer.Serialize(writer,oClassObject);
}
catch(InvalidOperationException ex)
{
string msg = ex.Message;
string stack = ex.StackTrace;
}
return strBuilder.ToString();
}

and exception occured with message "There was an error generating the XML
document."
how can I know where is the error occured the stack trace did not give usef
info

StackTrace : " at
System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter, Object
o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter, Object
o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter,
Object o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter,
Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
oClassType) in d:\\scorm\\test\\form1.cs:line 133"string

line 133 where I called oSerializer.Serialize(writer,oClassObject);

Any Suggestions?And that's all the stack trace? There isn't anything more in the error
description (no description of inner exception whatsoever)?

I think you'd get replies faster by asking this at
microsoft.public.dotnet.xml group (I sent this to that group).

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Raed Sawalha" <RaedSawalha@.discussions.microsoft.com> wrote in message
news:050B90D9-6524-46CD-BB20-E1FE3BAE0367@.microsoft.com...
> Hello when I serialize an object an error generated using this function
> public string SerializeObject(object oClassObject,System.Type oClassType)
> {
> XmlSerializer oSerializer = new XmlSerializer(oClassType);
> System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
> System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
> try
> {
> oSerializer.Serialize(writer,oClassObject);
> }
> catch(InvalidOperationException ex)
> {
> string msg = ex.Message;
> string stack = ex.StackTrace;
> }
> return strBuilder.ToString();
> }
> and exception occured with message "There was an error generating the XML
> document."
> how can I know where is the error occured the stack trace did not give
> usef
> info
> StackTrace : " at
> System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
> Object
> o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
> Object
> o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter,
> Object o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter,
> Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
> oClassType) in d:\\scorm\\test\\form1.cs:line 133" string
> line 133 where I called oSerializer.Serialize(writer,oClassObject);
> Any Suggestions?
Can you post the definition of the class you're trying to serialize?

If the class is not serializable, the XmlSerializer is going to have a
hard time turning it into an XML document :)

Greetings,
Wessel

--Original Message--
From: Raed Sawalha [mailto:RaedSawalha@.discussions.microsoft.com]
Posted At: Sunday, April 10, 2005 11:25 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: There was an error generating the XML document.
Subject: There was an error generating the XML document.

Hello when I serialize an object an error generated using this function
public string SerializeObject(object oClassObject,System.Type
oClassType)
{
XmlSerializer oSerializer = new XmlSerializer(oClassType);
System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
try
{
oSerializer.Serialize(writer,oClassObject);
}
catch(InvalidOperationException ex)
{
string msg = ex.Message;
string stack = ex.StackTrace;
}
return strBuilder.ToString();
}

and exception occured with message "There was an error generating the
XML
document."
how can I know where is the error occured the stack trace did not give
usef
info

StackTrace : " at
System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object
o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
Object
o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter,
Object o, XmlSerializerNamespaces namespaces)\r\n at
System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter,
Object o)\r\n at Test.Form1.SerializeObject(Object oClassObject, Type
oClassType) in d:\\scorm\\test\\form1.cs:line 133"string

line 133 where I called oSerializer.Serialize(writer,oClassObject);

Any Suggestions?
Hello Raed,

Your code looks ok. You'll need to dig down into the InnerException ... buried
down in there you'll find the root cause of the problem.

--
Matt Berther
http://www.mattberther.com

> Hello when I serialize an object an error generated using this
> function
> public string SerializeObject(object oClassObject,System.Type
> oClassType)
> {
> XmlSerializer oSerializer = new XmlSerializer(oClassType);
> System.Text.StringBuilder strBuilder = new
> System.Text.StringBuilder();
> System.IO.TextWriter writer = new System.IO.StringWriter(strBuilder);
> try
> {
> oSerializer.Serialize(writer,oClassObject);
> }
> catch(InvalidOperationException ex)
> {
> string msg = ex.Message;
> string stack = ex.StackTrace;
> }
> return strBuilder.ToString();
> }
> and exception occured with message "There was an error generating the
> XML
> document."
> how can I know where is the error occured the stack trace did not give
> usef
> info
> StackTrace : " at
> System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
> Object o, XmlSerializerNamespaces namespaces, String
> encodingStyle)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter,
> Object o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(T extWriter
> textWriter, Object o, XmlSerializerNamespaces namespaces)\r\n at
> System.Xml.Serialization.XmlSerializer.Serialize(T extWriter
> textWriter, Object o)\r\n at Test.Form1.SerializeObject(Object
> oClassObject, Type oClassType) in d:\\scorm\\test\\form1.cs:line 133"
> string
> line 133 where I called oSerializer.Serialize(writer,oClassObject);
> Any Suggestions?

Tuesday, March 13, 2012

thread was being aborted

I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an exception:

-----

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()

------

Here's my code

Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")

'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))

'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()

Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Sub

Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next

Catch ex As Exception
ExceptionManager.Publish(ex)

End Try

End Function

_____
DC GGringo,

you might want to replace Response.End() with Response.Flush.

Let me know if this works for you.

Daniel Walzenbach

"DC Gringo" <dcgringo@.visiontechnology.net> schrieb im Newsbeitrag
news:OPF77XjjFHA.3348@.tk2msftngp13.phx.gbl...
>I have some code that creates and writes to an excel file. Right as I
>response.end() to avoid HTML in the Excel document, I get an exception:
> -----
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> ------
> Here's my code
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
> Try
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> 'Output Data
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Function
> _____
> DC G
Daniel,

Sorry, it didn't work. I didn't get the error, but the HTML returned to the
Excel file. Putting the response.flush() after the response.close() or vice
versa still generated the error.

_____
DC G

"Daniel Walzenbach" <daniel.walzenbach@.newsgroup.nospam> wrote in message
news:%23u1QBEkjFHA.1148@.TK2MSFTNGP12.phx.gbl...
> Gringo,
> you might want to replace Response.End() with Response.Flush.
> Let me know if this works for you.
> Daniel Walzenbach
>
> "DC Gringo" <dcgringo@.visiontechnology.net> schrieb im Newsbeitrag
> news:OPF77XjjFHA.3348@.tk2msftngp13.phx.gbl...
>>I have some code that creates and writes to an excel file. Right as I
>>response.end() to avoid HTML in the Excel document, I get an exception:
>>
>> -----
>>
>> An attempt to log the following error
>> failed:System.Threading.ThreadAbortException: Thread was being aborted.
>> at System.Threading.Thread.AbortInternal()
>> at System.Threading.Thread.Abort(Object stateInfo)
>> at System.Web.HttpResponse.End()
>>
>> ------
>>
>> Here's my code
>>
>>
>> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
>> System.EventArgs)
>>
>> Try
>> Dim ds As New DataSet
>> Dim da As New SqlDataAdapter(Session("savedShasSql"),
>> connection1.conString)
>> da.Fill(ds, "ShasExcel")
>> Dim dt As DataTable = ds.Tables("ShasExcel")
>>
>> 'This code was dumping html into the spreadsheet
>> 'Response.ContentType = "application/ms-excel"
>> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
>> 'Response.Write(ConvertDtToTDF(dt))
>>
>> 'This is the new code
>> Response.ContentType = "application/ms-excel"
>> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
>> Response.Clear()
>> Response.Write(ConvertDtToTDF(dt))
>> Response.End()
>>
>> Catch ex As Exception
>> ExceptionManager.Publish(ex)
>> End Try
>>
>> End Sub
>>
>>
>>
>> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
>>
>> Try
>>
>> Dim dr As DataRow, ary() As Object, i As Integer
>> Dim iCol As Integer
>>
>> 'Output Column Headers
>> For iCol = 0 To dt.Columns.Count - 1
>> Response.Write(dt.Columns(iCol).ToString & vbTab)
>> Next
>>
>> Response.Write(vbCrLf)
>>
>> 'Output Data
>>
>> For Each dr In dt.Rows
>> ary = dr.ItemArray
>> For i = 0 To UBound(ary)
>> Response.Write(ary(i).ToString & vbTab)
>> Next
>> Response.Write(vbCrLf)
>> Next
>>
>> Catch ex As Exception
>> ExceptionManager.Publish(ex)
>>
>> End Try
>>
>> End Function
>>
>> _____
>> DC G
>>
Yes, this is the way ASP.NET attempts to insure that the processing halts
for the current request -- they throw a ThreadAbortException. Sort of odd,
eh? Well, the magic with a ThreadAbortException is that if you put a try/catch
around it, it still gets thrown outside your catch -- they're doing this
so you don't catch their attempt to terminate the request. So, in short,
it's just how it works.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I have some code that creates and writes to an excel file. Right as I
> response.end() to avoid HTML in the Excel document, I get an
> exception:
> -----
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being
> aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> ------
> Here's my code
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e
> As System.EventArgs)
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition",
> "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition",
> "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
> Try
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> 'Output Data
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Function
> _____
> DC G
a Response.End() does a flush, then kills the current thread (to stop
continued processing). ignore the thread abort in your catch

-- bruce (sqlwork.com)

"DC Gringo" <dcgringo@.visiontechnology.net> wrote in message
news:OPF77XjjFHA.3348@.tk2msftngp13.phx.gbl...
>I have some code that creates and writes to an excel file. Right as I
>response.end() to avoid HTML in the Excel document, I get an exception:
> -----
> An attempt to log the following error
> failed:System.Threading.ThreadAbortException: Thread was being aborted.
> at System.Threading.Thread.AbortInternal()
> at System.Threading.Thread.Abort(Object stateInfo)
> at System.Web.HttpResponse.End()
> ------
> Here's my code
>
> Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> Try
> Dim ds As New DataSet
> Dim da As New SqlDataAdapter(Session("savedShasSql"),
> connection1.conString)
> da.Fill(ds, "ShasExcel")
> Dim dt As DataTable = ds.Tables("ShasExcel")
> 'This code was dumping html into the spreadsheet
> 'Response.ContentType = "application/ms-excel"
> 'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> 'Response.Write(ConvertDtToTDF(dt))
> 'This is the new code
> Response.ContentType = "application/ms-excel"
> Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
> Response.Clear()
> Response.Write(ConvertDtToTDF(dt))
> Response.End()
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Sub
>
> Private Function ConvertDtToTDF(ByVal dt As DataTable) As String
> Try
> Dim dr As DataRow, ary() As Object, i As Integer
> Dim iCol As Integer
> 'Output Column Headers
> For iCol = 0 To dt.Columns.Count - 1
> Response.Write(dt.Columns(iCol).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> 'Output Data
> For Each dr In dt.Rows
> ary = dr.ItemArray
> For i = 0 To UBound(ary)
> Response.Write(ary(i).ToString & vbTab)
> Next
> Response.Write(vbCrLf)
> Next
> Catch ex As Exception
> ExceptionManager.Publish(ex)
> End Try
> End Function
> _____
> DC G