Using ASP page to download .wmv file

R

RJT

I want to set up an asp page that will download a .wmv (Windows Media video)
file to the user and save it in a directory of the user's choice on the
user's computer. I think this is an elementary situation using
Response.ContentType, and the MIME type for a .wmv file, but I don't know
exactly how.

Thanks very much for any help.
 
D

Daniel Fisher\(lennybacon\)

Response.Clear();
Response.ContentType = "video/x-ms-wmv";
Response.AddHeader("Content-Disposition", "attachment; filename=" +
Path.GetFileName(_filePath));
Response.AddHeader("Content-Length", new
FileInfo(_filePath).Length.ToString());

Response.Buffer = false;
FileStream _fileStream = null;
byte[] _buffer = new byte[this.m_bufferSize];
long _byteCount;
try
{
_fileStream = File.OpenRead(_filePath);
while ((_byteCount = _fileStream.Read(_buffer, 0, _buffer.Length)) > 0)
{
if(Response.IsClientConnected)
{
Response.OutputStream.Write(_buffer, 0, _buffer.Length);
Response.Flush();
}
else
{
//OnDownloadCancelled();
return;
}
}
//OnDownloadCompleted();
}
catch(Exception _ex)
{
throw _ex;
}
finally
{
_fileStream.Close();
context.Response.End();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top