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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:37:20+00:00 2026-05-14T21:37:20+00:00

I thought MVC was supposed to make all this easier but I’m trying various

  • 0

I thought MVC was supposed to make all this easier but I’m trying various ways and getting issues.

If I try the accepted answer for this question (changing the content type accordingly)… How to create file and return it via FileResult in ASP.NET MVC?

…I get into trouble because my encoding in the xml file is UTF-16.

The error I get is:

Switch from current encoding to specified encoding not supported.

This suggests that somewhere I need to tell MVC that I want UTF-16. Alternatively I want a different method that uses binary and not text.

  • 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-14T21:37:21+00:00Added an answer on May 14, 2026 at 9:37 pm

    This is what I’ve settled for:

    public FileStreamResult DownloadXML()
    {
        string name = "file.xml";
        XmlDocument doc = getMyXML();
        System.Text.Encoding enc = System.Text.Encoding.Unicode;
        MemoryStream str = new MemoryStream(enc.GetBytes(doc.OuterXml));
    
        return File(str, "text/xml", name);
    }
    

    I don’t think this is perfect and I could probably just use a FileContentResult and not bother with the memory stream. Also, I don’t think IE likes the unicode. It complains that “A name was started with an invalid character” despite the xml being fine and happily opening in firefox.

    However it seems to do the job.

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

Sidebar

Related Questions

I'm trying to make a simple website using mvc but I'm a little confused
I thought I had resolved this but I obviously haven't and was hoping someone
I thought this would be fairly simple but it turns out not to work
I thought I'd find more about this topic but I didn't. I have to
I am new to ASP.NET MVC. I am trying to create what I thought
I really HATE to ask this because I thought this is supposed to be
Working with MVC 2 ad with the help of some friends I thought all
I am trying to start a new MVC project with tests and I thought
I thought this would be very simple but I'm struggling a little. I'm working
Thought my range of search options would easily find this. I wish to combine

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.