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

The Archive Base Latest Questions

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

I need to create an ActionResult in an ASP.NET MVC application which has a

  • 0

I need to create an ActionResult in an ASP.NET MVC application which has a .csv filetype.

I will provide a ‘do not call’ email list to my marketing partners and i want it to have a .csv extension in the filetype. Then it’ll automatically open in Excel.

 http://www.example.com/mailinglist/donotemaillist.csv?password=12334

I have successfully done this as follows, but I want to make sure this is the absolute best and recommended way of doing this.

    [ActionName("DoNotEmailList.csv")]
    public ContentResult DoNotEmailList(string username, string password)
    {
            return new ContentResult()
            {
                Content = Emails.Aggregate((a,b)=>a+Environment.NewLine + b), 
                ContentType = "text/csv"
            };
    }

This Actionmethod will respond to the above link just fine.

I’m just wondering if there is any likelihood of any unexpected conflict of having the file extension like this with any different version of IIS, any kind of ISAPI filter, or anything else I cant think of now.

I need to be 100% sure because I will be providing this to external partners and don’t want to have to change my mind later. I really cant see any issues, but maybe theres something obscure – or another more “MVC” like way of doing this.

  • 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-11T20:58:34+00:00Added an answer on May 11, 2026 at 8:58 pm

    I think your Response MUST contain “Content-Disposition” header in this case. Create custom ActionResult like this:

    public class MyCsvResult : ActionResult {
    
        public string Content {
            get;
            set;
        }
    
        public Encoding ContentEncoding {
            get;
            set;
        }
    
        public string Name {
            get;
            set;
        }
    
        public override void ExecuteResult(ControllerContext context) {
            if (context == null) {
                throw new ArgumentNullException("context");
            }
    
            HttpResponseBase response = context.HttpContext.Response;
    
            response.ContentType = "text/csv";
    
            if (ContentEncoding != null) {
                response.ContentEncoding = ContentEncoding;
            }
    
            var fileName = "file.csv";
    
            if(!String.IsNullOrEmpty(Name)) {
                fileName = Name.Contains('.') ? Name : Name + ".csv";
            }
    
            response.AddHeader("Content-Disposition",
                String.Format("attachment; filename={0}", fileName));
    
            if (Content != null) {
                response.Write(Content);
            }
        }
    }
    

    And use it in your Action instead of ContentResult:

    return new MyCsvResult {
        Content = Emails.Aggregate((a,b) => a + Environment.NewLine + b)
        /* Optional
         * , ContentEncoding = ""
         * , Name = "DoNotEmailList.csv"
         */
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to create a custom DNS name server using C which will check against
I need to create a WP site which will have multiple subjects. Each subject
What is the correct way of generating random numbers in an ASP.NET MVC application
I have created an otherwise empty ASP.NET MVC 3 application with 2 controllers, HomeController
is it allowed in ASP.NET MVC to alter the submitted values? [HttpPost] public ActionResult
I'm using ASP.NET MVC and I have a model class which represents a peice
Many classes and methods within my ASP.NET MVC 3 application are decorated with the
I'm writing a new asp.net mvc application and I've been toying with the idea
I have small Asp MVC 3 project where I need to create link to
I need to implement a file download in ASP.NET MVC. Searching the Web, 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.