Skip to content

Instantly share code, notes, and snippets.

@Gerhard-ZA
Created February 13, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gerhard-ZA/4fb8b62501783714fc565cef66ca1d21 to your computer and use it in GitHub Desktop.
Save Gerhard-ZA/4fb8b62501783714fc565cef66ca1d21 to your computer and use it in GitHub Desktop.
Convert files to byte array memory objects
public static string AddFilesToTransaction(RestService rs, string docNbr, string filePath, string fileName, string entity)
{
string result = "#UPLOADING DOCS";
try
{
byte[] filedata;
using (FileStream file = File.Open(filePath, FileMode.Open))
{
filedata = new byte[file.Length];
file.Read(filedata, 0, filedata.Length);
//Add the file
Stream fileToAttach = new MemoryStream(filedata);
result = rs.PutFile(entity, docNbr, fileName, fileToAttach);
}
}
catch (Exception msg)
{
result = msg.Message;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment