Questions tagged [fileresult]

69 questions
63
votes
6 answers

Stream file using ASP.NET MVC FileContentResult in a browser with a name?

Is there a way to stream a file using ASP.NET MVC FileContentResult within the browser with a specific name? I have noticed that you can either have a FileDialog (Open/Save) or you can stream the file in a browser window, but then it will use the…
Anup Marwadi
  • 2,245
  • 4
  • 23
  • 39
17
votes
1 answer

Redirecting to MVC ActionResult from FileResult

This might be a simple one but here goes: I'm implementing an excel downloadable report in my MVC3 application. I've used this method in the past and it's worked perfectly, however in this case, there is a chance that sales data may not exist for…
109221793
  • 15,397
  • 37
  • 100
  • 157
15
votes
5 answers

Completed event for FilePathResult

I want to do something after user finishes downloading public class TestController : Controller { public FilePathResult Index() { return File("path/to/file", "mime"); } } What I tried is to add the following events to test…
Almis
  • 3,064
  • 2
  • 25
  • 52
9
votes
7 answers

What is the best way to return File or ErrorMessage from Asp.net-mvc controller action?

I have the following javascript code and controller action in my ASP.NET-MVC project: Javascript: $("#exportPPT").live('click', function (e) { window.location.href = "/Initiative/GenerateFile" + GenerateParams(); }); C# Controller: public…
leora
  • 163,579
  • 332
  • 834
  • 1,328
9
votes
1 answer

How to return error message from FileResult method in asp.net MVC 4 application?

I have a fileresult method in asp.net mvc4 that returns a report in an excel file. Now how can i return an error message from this method if my conditions are not met !! Since we can only return a file from this method ?! Thnks
Ashkan
  • 566
  • 1
  • 6
  • 14
8
votes
1 answer

Is it possible to get byte[] from FileResult?

Is it possible to get byte[] from FileResult in C#?
DmitryBoyko
  • 32,983
  • 69
  • 281
  • 458
6
votes
1 answer

ASP.NET MVC returning zipped file with FileResult is missing extension

I have a zipped file which I am trying to stream to client: public FileResult GetFiles() { return File("test.zip", "application/zip"); } The file downloads but without the ".zip" extension.
fearofawhackplanet
  • 47,230
  • 49
  • 149
  • 249
5
votes
2 answers

ASP MVC3 FileResult with accents + IE8 - bugged?

If the file name contains accents, it works as expected in Opera, FF, Chrome and IE9. But in IE8 file type is "unknown file type", and shows "file" as the file name (actually the last part of the URL). Does anyone know a workaround? Other than…
Akos Lukacs
  • 1,949
  • 1
  • 14
  • 21
5
votes
1 answer

ASP.NET MVC FilePathResult: How to return an html file not found?

The following code is hopefully a correct way to return an image that exists on disk using ASP.NET MVC 3: public FilePathResult GetThumbnail(string imageName) { if( !String.IsNullOrEmpty(imageName) && Regex.IsMatch(imageName,…
Zachary Scott
  • 20,070
  • 32
  • 114
  • 195
5
votes
2 answers

FileResult buffered to memory

I'm trying to return large files via a controller ActionResult and have implemented a custom FileResult class like the following. public class StreamedFileResult : FileResult { private string _FilePath; public StreamedFileResult(string…
Scott Wilson
  • 629
  • 1
  • 6
  • 17
4
votes
1 answer

HTTP HEAD Request and System.Web.Mvc.FileResult

I'm using BITS to make requests to a ASP.NET MVC controller method named Source that returns a FileResult. I know the type FilePathResult uses HttpResponse.TransmitFile, but I don't know if HttpResponse.TransmitFile actually writes the file to the…
Michael Nero
  • 1,387
  • 13
  • 23
4
votes
0 answers

Slow response for returning a file using a FileResult controller?

I'm attempting to build a speed test app for our customers connecting to our e-labs. I want to test their download speed in Mbps. The logic I came up with is; upon click event, record the startTime, make an ajax call to a FileResult controller to…
JReam
  • 888
  • 2
  • 11
  • 27
3
votes
2 answers

Asp.Net MVC 5 FileResult always download file with ANSI encoding

I have this part of code Response.Charset = _encodingcode; Response.AddHeader("Content-Encoding", _encodingcode); Response.HeaderEncoding = Encoding.GetEncoding(_encodingcode); Response.ContentEncoding =…
GomuGomuNoRocket
  • 521
  • 1
  • 4
  • 27
3
votes
1 answer

Download an image generated dynamically rather than display in browser

I created a Action that convert the content of an URL(HTML) into an Image (JPG), and than, return it to me, however, the browser is downloading it instead showing. The Image is generated dynamically, I don't have it in hard disk. My code is the…
Dan
  • 1,082
  • 3
  • 14
  • 40
3
votes
2 answers

Show or Download File Correctly in ASP.NET MVC3 When File Type Isn't Text or Picture

This is My Action: public FileResult ShowFile(long Id) { DAL.Files.File file = new DAL.Files.FileAccess().GetById(Id); return File(file.Content, file.FileType); } GetById method return a file from SQL DB, when the file type is text or…
Saeid
  • 12,286
  • 26
  • 98
  • 166
1
2 3 4 5