Hi, I got error when I tried to join two files mp3 in ASP.NET C#
'System.IO.Stream' does not contain a definition for 'WriteTo'

How to fix that error? please help

Here is my codes:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.IO;
using System.Text;

public partial class mp3Manager : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e) {
		Response.Clear();
		Response.ContentType = "audio/mpeg";
		Response.AddHeader("Content-Disposition", "attachment; filename=1.mp3");
		WriteBytesToResponse(System.IO.File.ReadAllBytes(@"C:\inetpub\wwwroot\mp3\1.mp3"));
		WriteBytesToResponse(System.IO.File.ReadAllBytes(@"C:\inetpub\wwwroot\mp3\2.mp3"));
		Response.End();
	}

	private void WriteBytesToResponse(byte[] sourceBytes) {
		using (Stream sourceStream = new MemoryStream(sourceBytes, false)) {
			sourceStream.WriteTo(Response.OutputStream);
		}
	}
}

The error is saying clearly that there is not Write method exist in System.IO.Stream Class.

Stream Class contain Write and WriteByte method. So use Write or WriteByte method and it will fix your error.

Hi, I got error when I tried to join two files mp3 in ASP.NET C#
'System.IO.Stream' does not contain a definition for 'WriteTo'

How to fix that error? please help

Here is my codes:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.IO;
using System.Text;

public partial class mp3Manager : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e) {
		Response.Clear();
		Response.ContentType = "audio/mpeg";
		Response.AddHeader("Content-Disposition", "attachment; filename=1.mp3");
		WriteBytesToResponse(System.IO.File.ReadAllBytes(@"C:\inetpub\wwwroot\mp3\1.mp3"));
		WriteBytesToResponse(System.IO.File.ReadAllBytes(@"C:\inetpub\wwwroot\mp3\2.mp3"));
		Response.End();
	}

	private void WriteBytesToResponse(byte[] sourceBytes) {
		using (Stream sourceStream = new MemoryStream(sourceBytes, false)) {
			sourceStream.WriteTo(Response.OutputStream);
		}
	}
}
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.