hi friends can anyone tell me how to play videos using Windows Media Player in ASP.NET 2.0 using c#.

please help, i am novice programmer in asp.net and c#

Dani AI

Generated

The question from is commonly solved two ways: embed the Windows Media Player ActiveX control in the ASPX page (works in Internet Explorer with the WMP plugin/codecs installed), or serve modern formats via the HTML5 <video> element for cross‑browser compatibility. The links posted by and are useful starting points; below is a concise, distilled approach plus a few practical cautions.

Minimal WMP embed (client must support ActiveX):

<object id="MediaPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="640" height="360">
  <param name="URL" value="/media/sample.wmv" />
  <param name="AutoStart" value="false" />
  <param name="uiMode" value="full" />
  <a href="/media/sample.wmv">Download the video</a>
</object>

To set the media URL from C# in code-behind, render the object markup into a server control (for example, an asp:Literal) so the path can be built with ResolveUrl/Server.MapPath. For streaming large files, prefer Response.TransmitFile over loading bytes into memory:

protected void StreamFile(string virtualPath)
{
    string physical = Server.MapPath(virtualPath);
    Response.Clear();
    Response.ContentType = "video/x-ms-wmv";
    Response.AddHeader("Content-Length", new System.IO.FileInfo(physical).Length.ToString());
    Response.TransmitFile(physical);
    Response.End();
}

Practical notes and pitfalls:

  • ActiveX embedding is IE-only; modern browsers and mobile devices will not run it. For broad support, provide an HTML5 <video> fallback (H.264 MP4 + WebM) or use a JS player.
  • Ensure IIS has correct MIME types for the video extensions (e.g., .wmv -> video/x-ms-wmv, .mp4 -> video/mp4).
  • For seeking and robust streaming, serve static files via IIS or implement HTTP range support; a simple TransmitFile may not handle range requests.
  • Client machines must have appropriate codecs for WMV; if not, playback will fail even when markup is correct.

This summary complements the demo links already posted and focuses on practical, working patterns for ASP.NET 2.0 + C#.

Recommended Answers

All 2 Replies

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.