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

  • Home
  • SEARCH
  • 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 8722481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:25:49+00:00 2026-06-13T07:25:49+00:00

In a Controller in my ASP.Net MVC app, I serialize a class, and am

  • 0

In a Controller in my ASP.Net MVC app, I serialize a class, and am trying to offer up the contents for immediate download.

So far, I’ve got my controller returning a FileStreamResult

    public FileStreamResult Create(MyViewMode vm)
    {
        var xml= _mySerializer.SerializeToXml(vm);

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
        return new FileStreamResult(ms, "application/xml");
    }

This works, however it’s outputting the XML in the browser.

Is there a way I can have it download the file as MyXml.xml for example?

  • 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-06-13T07:25:50+00:00Added an answer on June 13, 2026 at 7:25 am

    This seems to do what you want:

    public class HomeController : Controller
    {
        public ActionResult MyXml()
        {
            var obj = new MyClass {MyString = "Hello", MyInt = 42, MyBool = true};
            var ser = new XmlSerializer(typeof(MyClass));
            var stream = new MemoryStream();
            ser.Serialize(stream, obj);
            stream.Position = 0;
            return File(stream, "application/xml", "MyXml.xml");
        }
    
        public class MyClass
        {
            public string MyString { get; set; }
            public int MyInt { get; set; }
            public bool MyBool { get; set; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a ASP.NET MVC controller like this [Authorize] public class ObjectController : Controller
I've just created asp.net mvc 4 app and added default webapi controller public class
In my Controller in a Asp.net MVC 1 app I want to use UpdateModel
Is there a class in the ASP.NET MVC framework that represents a controller name
In my ASP.NET MVC app, I'm handling errors by overriding OnException in the controller.
I'm trying to improve the performance of an ASP.NET MVC app. Pages take about
I'm trying to verify the behaviour of my ASP.Net MVC app when an unexpected
I've been trying to implement jQuery's grid function in my Asp.Net MVC app. I'm
I've been trying to create an ASP.net - MVC app that uses entity framework
In my Asp.net MVC app, I have two methods on a controller, one for

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.