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 6703563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:11:10+00:00 2026-05-26T07:11:10+00:00

I have a fileupload control where i can upload xml documents. The XML files

  • 0

I have a fileupload control where i can upload xml documents.

The XML files will be encoded in unicode format. I want to convert them to UTF8, so they can render as a proper xml file.

Im saving the uploaded file in a hiddenfield as a hex string and sends it to a generic handler. What i want is a result that i can create an xml from. At the moment my string looks like this:

"??<\0?\0x\0m\0l\0 \0v\0e\0r\0s\0i\0o\0n\0=\0\"\01\0.\00\0\"\0 \0e\0n\0c\0o\0d\0i\0n\0g\0=\0\"\0I\0S\0O\0-

Instead of

<?xml version="1.0".. etc

Code:

if (fileUpload.PostedFile.ContentType == "text/xml")
{
      Stream inputstream = fileUpload.PostedFile.InputStream;

      byte[] streamAsBytes = (ConvertStreamToByteArray(inputstream));

      string stringToSend = BitConverter.ToString(streamAsBytes);

      xmlstream.Value = stringToSend;

      sendXML.Visible = true;
      infoLabel.Text = "<b>Selected XML: </b>" + fileUpload.PostedFile.FileName;
}

handler.ashx:

if (HttpContext.Current.Request.Form["xmldata"] != null)
        {
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;

            string xmlstring = HttpContext.Current.Request.Form["xmldata"];

            byte[] data = xmlstring.Split('-').Select(b => Convert.ToByte(b, 16)).ToArray();

            string complete = System.Text.ASCIIEncoding.ASCII.GetString(data);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(complete);

            HttpContext.Current.Response.Write(doc.InnerXml);
        }

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-26T07:11:11+00:00Added an answer on May 26, 2026 at 7:11 am

    It’s not at all clear that you really should do this. XML files can declare their own encoding, and it looks like yours is declaring an encoding starting with “ISO” (that’s where the data you’ve given us stops). That’s probably not UTF-8.

    Basically, I don’t think you should be treating the data as text in handler.ashx. Just get XmlDocument to parse it from a stream. It’s not really clear exactly how your upload code is sending the data, but you should try to mess with it as little as possible.

    It’s possible that your current code would actually work fine if you just changed this:

    string complete = System.Text.ASCIIEncoding.ASCII.GetString(data);
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(complete);
    

    to this:

    XmlDocument doc = new XmlDocument();
    doc.Load(new MemoryStream(data));
    

    However, the hex part is pretty ugly. If you really need to represent the binary data as text, I’d strongly recommend using Base64 instead of hex:

    string text = Convert.ToBase64String(binary);
    ...
    byte[] binary = Convert.FromBase64String(text);
    

    … there’s no need to convert each byte separately and split the string on hyphens etc.

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

Sidebar

Related Questions

I have a FileUpload control in the Source page. On the Upload button handler,
I have a Web Application in which I am using asp:FileUpload Control to upload
I am using FileUpload Control to upload images, I can select the image using
I have a web page on which users can upload text files (but a
I have a user control that will render a textbox or file upload. I
I have been using normal file upload element to upload files and validate them.
I have a page that have fileupload control, on the submission of the form,
I have a update panel, in the update panel I have fileupload control and
I'm running into an issue where I have a FileUpload control in an UpdatePanel.
Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control. We have licenses for Telerik. I

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.