ASP.NET MVC Response file should not download - asp.net-mvc

I am generating a .cxml file on the server and pushing it to the browser based on certain queries. If I just link to a .cxml, it does what I expected and opens it in the respective application.
How can I generate a file and push it to the browser just like if it was linked to a file without it asking me to download it?
The link looks something like:
http://localhost/MyController/GetFile?q=TheQueryStringParam
Thanks.

Simply Response.Write(yourFileText) should do the trick

Related

OpenERP Reports always in PDF

I'm new in OpenERP and I'm starting to know the application.
I hope you allow me to post this kind of questions on the forum.
Whenever I issue any listing or report in OpenERP, the application generates a PDF file to be opened or downloaded. Is there any way to make these listings and reports directly into a browser window so I can print them directly from the browser instead of download/open PDF files?
Thank you very much
Paulo Matos
[https://code.launchpad.net/~openerp-india/openerp-india/web_pdf_viewer-pga
You can use this module to open directly in browser.
Just copy this module to your web/addons folder of openerp web
Hope its work

open an excel file located on the server instead of download it MVC

I'm building a Reporting web application right now with MVC3 and I've come up to a couple problems.
My goal is to have it able to generate and view Crystal Reports, SSRS reports, and Excel documents.
Right now I'm working on the Excel segment and I'm running into more trouble than I thought I would. First off, when I link directly to the file, it either opens inside the browser or it downloads it from the server and if the user makes changes it doesn't actually save it to the true file on the server.
I've tried both linking to the file directly using Razor and a ViewModel with the path to the document as well as directing it to an action that returned a File.
I've also tried linking it to a shortcut to the actual file thinking that if I could open the shortcut it would open the file the way I wanted it to and unfortunately it didn't really open at all.
The users already have access to the files on the server through a network drive, so as of right now they can go into the server, open the excel document, edit and save it no problem. I want to duplicate this effect through a link. The program already has a file browser built, so I can browse between the files and make links to the reports.
Thanks in advance!
Since they are apparently on a network drive, you can just link to the files directly, relative to the user?
For example: a link to file://///SERVERNAME/folder/
I tested it between two computers on the network, and that seems to work. However, you still get a popup asking that you want to do with the file, open or save. (both in firefox and IE)
Note: Yes, that many slashes seem necessary, lol

How To Dynamically Route to Downloads

Basically, this is what my app does:
It sends an AJAX request
The server creates a file
The server sends back the URL of the
file location
The client-side will attempt to
create a dialog to download the file
at that location (probably using a
frame? I haven't got this far yet).
My question is, how do I dynamically route to the files I create so that they are accessible when you browse to them? If I don't add a route for them, then they will get a 404 if they try and access the directory they're in.
The files are currently stored in a folder in public.
Would the best way to deal with this make the folder somehow not require a route, so that it can be browsed to directly, and then have an index page on it so they can't view the full list of files? If so, please let me know how I can accomplish this. And on a side note, if you have an idea of how I can accomplish JS displaying the download dialog let me know.
It's Rails 3 by the way.
Thanks!
For a full private set of files: choose a place for your files outside your public directory, then configure X-SendFile support in your web server and finally use send_file in your rails application.

Saving the file on a user selected location using rails

We are developing a functionality that allows the users to save the downloaded file. We are struggling to get a popup where the user can select a target location / folder to save his file. Can this be achieved using rails?
I think you're looking for send_file - it's very easy to use.
I think it depends on the content-type and similar headers you're returning to the user.
Try returning something like:
header('Content-disposition: attachment; filename=movie.mpg');
header('Content-type: video/mpeg');
EDIT: I am assuming you're able to generate headers and returning a file to the user by HTTP (no simple links to files)
I think you are trying to give something like file browser dialog box which allows client to save file on a particular location.
In case you are trying to give this from your server then I should say it is not possible due to security restriction which browser makers have applied to ensure client's security.
Another way is to let client download your browser plugin/activeX Control which basically is control over client's machine then you can do what you want i.e. something like this also.
I think without this the filetype downloaded by client is identified (based on headers) by browser and it opens the file save dialog box automatically and you cant enter into client's secure arena.
I think you want download file option. For example on hitting a URL you
want user to download a zip file code for it you can do something like
this:
class MyController < ApplicationController
def downloadzip
send_file "path_to_file", :type=>"application/zip"
end
end

How to send a file to the browser using ASP.NET MVC controller action?

I have an application where I allow my users to upload a file of any type. I save this in the file system on the server. The application will only be accessed by two users, so I don't need to worry about uploading any dodgy files.
How do I allow my user to press a button on an MVC form to request the file be sent back via the browser and be presented with the standard save/open dialog?
I want to return any type of file, and the example I've found always specify the type of file being returned. Is there a simple example of this?
See FileResult and derived classes.
An alternative approach is to set HttpContext.Response.ContentType to the proper mimetype and then writing the contents of the file with HttpContext.Response.OutputStream.Write ().
Useful if, for example, the data is not in a local file but stored in a database as a binary blob.

Resources