A MemoryStream is my preferred method of passing around file data throughout my .Net applications. The following code details a simple way to download a file and place it in the memory stream.
Download a PDF from a remote location and store data in a MemoryStream. The MemoryStream needs will be accessed multiple times in a single instance from other OO objects.
Microsoft .Net FCL (Framework Class Library)
The following code is deigned for use in a class file that is a part of an object oriented architecture.
// Sample Url, Watch for Line Breaks
static string pdfUrl =
// Member variable to store the MemoryStream Data
private MemoryStream pdfMemoryStream;
// Public MemoryStream property containing PDF Data
public MemoryStream PdfMemoryStream
// Check to see if the MemoryStream has already been created,
// if not, then create memory stream
if (this.pdfMemoryStream == null)
WebClient client = new WebClient();