Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
https://www.codeproject.com/Questions/1187473/How-to-save-bytearray-to-PDF[^]

I am working on project in which i need to store byte array as PDF.

After some research, I am able to get file type of the byte array.

Is it possible to get file name from the byte array?

What I have tried:

I have tried methods from this link.
http://stackoverflow.com/questions/8741968/get-file-name-from-byte-array-or-stream[^]

It is throwing exception "Object reference not set to an instance of an object."
Posted
Updated 16-May-17 21:11pm
Comments
Richard MacCutchan 17-May-17 3:57am    
"Is it possible to get file name from the byte array?"
Only if the byte array contains the filename in the first place. A byte array is just that, an array of bytes, which mean nothing unless you know the exact structure of its content.

1 solution

If you have tried methods from a different site, the most sensible thing to do would be to ask a question of the person who wrote the code, not a different site completely.
The second most sensible thing would be to show the code you tried - as you tried it - by copy'n'pasting it into your question on the different site. Without that, everybody is just guessing what exactly you did...
The third most sensible thing (but the thing I'd have done first) would be to use the debugger to look at exactly what is going on when I ran the code.

But...if you have a byte array and that is all, it doesn't have a filename - those are only available within the operating system file system for actual files, and a byte array does not have any file associated with it, even if it was read from or has been written to a file. Think about it: when you change a file name it makes no change at all to the file content - and an array of bytes is just the file content without any other "wrapping" material that you might get with a filestream. So at a guess, you are trying to cast a byte array to a stream, and assuming that that will give you a file name. It won't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900