How to upload video files like wmv,etc in an application folder and how to download that video file in media player usnig asp.net +c#.

Dani AI

Generated

As asked about uploading WMV (and similar) files and making them downloadable/playable, and since already pointed to a thread, the following is a compact, practical pattern for ASP.NET + C# (WebForms). It shows a safe upload flow, how to serve the file so a client media player can open it, and a few important cautions that were missing from the thread.

Example: simple upload (ASPX + code-behind)

<!-- page.aspx -->
<asp:FileUpload ID="fuVideo" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
/* page.aspx.cs */
protected void btnUpload_Click(object sender, EventArgs e)
{
    if (!fuVideo.HasFile) return;
    string ext = Path.GetExtension(fuVideo.FileName).ToLowerInvariant();
    var allowed = new[] { ".wmv", ".mp4", ".avi" };
    if (!allowed.Contains(ext)) return; // validate
    string stored = Guid.NewGuid().ToString() + ext;
    string folder = Server.MapPath("~/App_Data/Videos");
    Directory.CreateDirectory(folder);
    string path = Path.Combine(folder, stored);
    fuVideo.SaveAs(path);
    // persist original name, stored name and metadata to DB
}

Serving/streaming to client (so Windows Media Player or browser can open):

protected void ServeVideo(string storedFile, string displayName)
{
    string path = Server.MapPath("~/App_Data/Videos/" + storedFile);
    if (!File.Exists(path)) { Response.StatusCode = 404; return; }
    Response.Clear();
    Response.ContentType = "video/x-ms-wmv"; // set per extension
    Response.AddHeader("Content-Disposition", "inline; filename=\"" + displayName + "\"");
    Response.TransmitFile(path); // efficient, avoids buffering whole file
    HttpContext.Current.ApplicationInstance.CompleteRequest();
}

Notes and cautions: adjust upload limits in web.config / IIS for large files; give the app pool write permission to the upload folder; prefer App_Data or a folder outside web root and serve via handler to enforce auth; whitelist extensions and (if possible) validate MIME/inspect file headers; use GUID names to avoid collisions and path-traversal; support HTTP Range requests if you need seeking in the player (static file serving or a range-aware handler). See ASP.NET FileUpload and HttpResponse.TransmitFile for details: FileUpload Class and HttpResponse.TransmitFile. For Content-Disposition behavior see Content-Disposition header.

Recommended Answers

All 3 Replies

S.That link details are working.

Really pleased that it worked.

Please mark this thread as closed if its solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.