private void DownloadEmbeddedResource(
string resourceName, Assembly resourceAssembly, string downloadFileName )
{
using ( Stream stream = resourceAssembly.GetManifestResourceStream( resourceName ) )
{
if ( stream != null )
{
Response.Clear();
string headerValue = string.Format( "attachment; filename={0}", downloadFileName );
Response.AppendHeader( "Content-Disposition:", headerValue );
Response.AppendHeader( "Content-Length", stream.Length.ToString() );
Response.ContentType = "text/xml";
var byteBuffer = new Byte[1];
using ( var memoryStream = new MemoryStream( byteBuffer, true ) )
{
while ( stream.Read( byteBuffer, 0, byteBuffer.Length ) > 0 )
{
Response.BinaryWrite( memoryStream.ToArray() );
Response.Flush();
}
}
Response.End();
}
}
}
I ended up using this method above. Thank you for helping me with the syntax tsilb. JohannesH, I would have used your recommendation if the resource wasn't already coming from a different assembly (Sorry, I should have cleared that up in my original question).
The code above works but I am encountering a fairly weird problem... After the method completes and the download finishes, the page is still never seems to come back to life and the mouse is still in hourglass mode like it still thinks work is being done. Any idea on how to remedy that?
Thanks again for all your help!