We are getting a input from a web service as a byte[] (which we process internally) and we need to upload to another web service which accepts only a file stream.
How can i to convert byte[] to a file stream without writing to disk in C#?
Edit: This is not duplicate. I am not asking how to convert byte[] to memory stream or file steam. I am asking how to convert byte[] to file stream without writing to disk. Please note that, I need to send the data as file steam to a third party web service, which I do not have access. This web service accepts only as file stream.
So far I have below code:
string fileWritePath = "c:\\temp\\test.docx"; //here fileContent is a byte[] File.WriteAllBytes(fileWritePath, fileContent); FileStream fileStream = new FileStream(fileWritePath, FileMode.Open, FileAccess.Read); I do not want to write the file to local disk and create file stream.
MemoryStreamand "store" the byte[] array into it.FileStreamis a wrapper on an handle for a resource (a file on the disk usually). this handle has a meaning only locally, on the computer where you create the FileStream. When you pass this object to an external web server, the underlying handle will not have any meaning.