How do I upload a video using ASP.NET?
It's not that hard to do. As dtb mentions, the user's browser will still ask the user for permission to download the file, and they may have a choice of choosing where to save the file. Thus, it will not be fully automatic.
Here is a link to a blog post explaining how this is done with web forms . The main part you are interested in is this:
Response.ContentType = "video/x-ms-wmv";
Response.AppendHeader("Content-Disposition","attachment; filename=MyMovie.wmv");
Response.TransmitFile( Server.MapPath("~/videos/MyMovie.wmv") );
Response.End();
Here is a link question that explains how to do this in MVC .
Based on your comment you want to do this in silverlight. I'm not an expert on Silverlight, but here's another Stack Overflow question that discusses the issue .
source to share
You can use WebClient
to download a wmv file and SaveFileDialog
to ask the user where to put it: -
void DownloadButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new SaveFileDialog();
if (dialog.ShowDialog().Value)
{
var web = new WebClient();
web.OpenReadCompleted = (s, args) =>
{
try
{
using (args.Result)
using (Stream streamOut = args.UserState As Stream)
{
Pump(args.Result, streamOut);
}
}
catch
{
// Do something sensible when the download has failed.
}
};
web.OpenReadAsync(UriOfWmv, ShowDialog.OpenFile());
}
}
private static void Pump(Stream input, Stream output)
{
byte[] bytes = new byte[4096];
int n;
while((n = input.Read(bytes, 0, bytes.Length)) != 0)
{
output.Write(bytes, 0, n);
}
}
However, there is currently no way to display download progress information. I was hoping this would go into Silverlight 4, but as far as I can see, it doesn't.
source to share