2

I generate the text file in my code using the stream writer using mvc format for web application . But my text file not download the my page? my sample code is below:

// file have the all values in stream writerformat

return File(file, "text/plain", "Export.txt");
1
  • I assume you already have the file created? and your issue is just how to render or return it to your user upon request? Commented Apr 12, 2013 at 13:06

2 Answers 2

1

try adding this before your return:

var cd = new System.Net.Mime.ContentDisposition
{
    FileName = "Export.txt", 
    Inline = false, 
};
Response.AppendHeader("Content-Disposition", cd.ToString());

return File(file, "text/plain");
Sign up to request clarification or add additional context in comments.

2 Comments

where i attach my my stream file?
yet also, not ask the download for file. I using the ajax for send the some information to my controller .its may be restrict the my rerun file ?
0

You can call a method that will give you your file stream like this:

public FileStreamResult DownloadFile()
{
    //
    // This part is where you build your file
    //
    // file should be a Stream
    return new FileStreamResult(file, "text/plain")
        {
            FileDownloadName = "optional_name_that_you_can_give_your_file"
        };
}

2 Comments

yet also, not ask the download for file. I using the ajax for send the some information to my controller .its may be restrict the my rerun file ?
I don't understand, can you rephrase your question? Better yet, update your question with the information you are trying to say to me here, so everybody can see it and learn more what you are trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.