Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:47:34+00:00 2026-05-30T20:47:34+00:00

HttpContext.Current.Response.ContentType = text/xml; HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; HttpPostedFile file = HttpContext.Current.Request.Files[0]; XDocument doc = XDocument.Load(XmlReader.Create(file.InputStream));

  • 0
HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;

HttpPostedFile file = HttpContext.Current.Request.Files[0];

XDocument doc = XDocument.Load(XmlReader.Create(file.InputStream));

var wr = new StringWriter();
doc.Save(wr);
HttpContext.Current.Response.Write(serializer.Serialize(wr.GetStringBuilder().ToString()));

This is resulting in a corrupt xml file. The string looks like this:

"\u003c?xml version=\"1.0\" encoding=\"utf-16\"?\u003e\r\n\u003cAuditSheet\u003e\r\n  \u003cPLANT_SITE_CUSTOMER_NAME\u003eZINIFEX HOBART SMELTER\u003c/PLANT_SITE_CUSTOMER_NAME\u003e\r\n 

Did i miss something obvious here? Do i need to remove the \r\n manually? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:47:35+00:00Added an answer on May 30, 2026 at 8:47 pm

    You shouldn’t be serializing the string.

    Instead, you should write directly to the HTTP response by calling doc.Save(response.Output).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little code: HttpContext.Current.Response.Clear(); if ( files.Contains( ',' ) ) { HttpContext.Current.Response.ContentType
System.Web.HttpContext.Current.Response.Cookies[ssocookies].Domain = System.Web.HttpContext.Current.Request.ServerVariables[SERVER_NAME].ToString().ToLower(); System.Web.HttpContext.Current.Response.Cookies[ssocookies].Value = tokenID.ToString(); System.Web.HttpContext.Current.Response.Cookies[ssocookies].Path = ~/; System.Web.HttpContext.Current.Response.Cookies[ssocookies].Expires = DateTime.Now.AddDays(7); Now what
In my .aspx: public static void DoStuff(XmlDocument doc) { HttpResponse response = HttpContext.Current.Response; string
Which is the most correct code? if (HttpContext.Current.Response.Cookies[authCookieName] != null) { HttpContext.Current.Response.Cookies[authCookieName].Value = New
HttpContext.Current.Items is a store that has a life span of the HTTP request. I'd
I'm debugging the HttpContext.Current.Request.Cookie values in an ASP.NET web application, and finding the only
What is the difference between HttpContext.Current.Request.IsAuthenticated and HttpContext.Current.User.Identity.IsAuthenticated? Which one would you use in
I have this code: Dim pathString As String = HttpContext.Current.Request.MapPath(Banking.mdb) Dim odbconBanking As New
Is HttpContext.Current ever null in a web Application (assuming threads are not being used)?
I reference the current page in a class with Page page = HttpContext.Current.CurrentHandler as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.