1

I am writing some XML data to the stringwriter. I want to pass the values in the stringwriter to the database but when I convert it to a string like

StringWriter.GetStringBuilder().ToString() it is converting all the " (double quotes) to \"

So when I pass that to database as parameter and when I try to read the data using openXML it's throwing an error.

Is there any work around for this ?

I am using ASP.NET 2.0
SQl server 2005

thanks!

1 Answer 1

4

I strongly suspect that you're looking at the debugger. That will show the escaped form, but the quotes won't actually be in the string if they shouldn't be.

I suggest you log the string somehow - then you'll see the real data, and my guess is that it won't contain the backslashes - assuming you haven't written any backslashes to the StringWriter to start with. How are you writing the data to the StringWriter? Is it possible that your problems are further upstream? (If you're writing the XML manually, I'd strongly recommend that you use an XML API instead. It's much less error-prone.)

What error are you getting when trying to read the XML back? What does it look like in the database?

I can pretty much guarantee that the problem won't be in StringWriter or StringBuilder - they don't perform any escaping.

On another note, is there any reason why you're calling GetStringBuilder().ToString() instead of just ToString()?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.