I need to set the save location in run time in mvc application . In windows appication we use the
System.Windows.Forms.SaveFileDialog();
But, what we use the web Application?
I need to set the save location in run time in mvc application . In windows appication we use the
System.Windows.Forms.SaveFileDialog();
But, what we use the web Application?
It is not clear what you want to save. In a web application you could use the file input to upload files to the server:
<input type="file" name="file" />
For more information about uploading files in an ASP.NET MVC application you may take a look at the following post
.
If on the other hand you want the user to be able to download some file from the server and prompted for the location where he wants to save this file you could return a File result from a controller action and specify the MIME type and filename:
public ActionResult Download()
{
var file = Server.MapPath("~/App_Data/foo.txt");\
return File(file, "text/plain", "foo.txt");
}
There are also other overloads of the File
method that allow you to dynamically generate a file and pass it as a stream to the client. But the important part to understand in a web application when downloading a file from a server is the Content-Disposition
header. It has 2 possible values: inline
and attachment
. For example with the above code the following header will be added to the response:
Content-Type: text/plain
Content-Disposition: attachment; filename=foo.txt
... contents of the file ...
When the browser receives this response from the server it will prompt the user with a Save As dialog allowing him to choose the location on his computer to store the downloaded file.
UPDATE:
Here's how you could achieve similar in a web application:
public ActionResult Download()
{
var file1 = File.ReadAllLines(Firstfilpath);
var file2 = File.ReadAllLines(2ndfilpath);
var mergedFile = string.Concat(file1, file2);
return File(mergedFile, "text/plain", "result.txt");
}