Last post Jul 17, 2015 05:13 AM by PatriceSc
Jul 17, 2015 04:36 AM|StudentRik|LINK
How can I send a PDF to a memory stream?
I have written and tried many things, the application is a console application and has a method that calls on a web service.
The method has a few parameters and one is a byte and I can't find an example that I understand for my purpose.
To test the method this is what I'm trying:
static void Main(string args)
using (FileStream fs = new FileStream(@"c:\DesktopShareFolder\DesktopShareFile\DesktopShareFile\CSS3_Cheat_Sheet.pdf", FileMode.Open))
Guid x = new Guid("AB5EC39F-E46A-41CE-95A7-1896F4887CDC");
byte bytes = new byte[fs.Length];
UploadFile(bytes, "FileName2", "email@example.com", true, x);
My Method has been changed many times but this is where I am now:
private static void UploadFile(byte fileBytes, string fileName, string email, bool copyMember, Guid memberId)
// Create instance of web Service
Upload srv = new Upload();
// Get file info from selected file
var fInfo = fileName;
// Get the length of file
// 16mb upload limit
double dLen = Convert.ToDouble(fileBytes.Length / 1000000);
if (dLen < 16)
using (var ms = new MemoryStream(fileBytes))
using (var br = new BinaryReader(ms))
byte data = null;
for (int i = 0; i < fileBytes.Length; i++)
data = br.ReadBytes(fileBytes[i]);
// Connect to web service
srv.UploadFile(data, fInfo, email, copyMember, RetrieveCompanyName(memberId));
catch (Exception ex)
Jul 17, 2015 05:13 AM|PatriceSc|LINK
Why a MemoryStream? It seems you need a byte array with the file content so you could likely just use
Also if it still fails, it's best to explain what happens when the code you are showing runs.