开发者

creating a file from input stream

开发者 https://www.devze.com 2023-01-01 19:28 出处:网络
My component will receive a pdf file as a filestream from which I will need to create a file. For testing purposes I am trying to read a file using the filestream object and recreate it at a differen

My component will receive a pdf file as a filestream from which I will need to create a file.

For testing purposes I am trying to read a file using the filestream object and recreate it at a different location. But the recreated file is created blank. the recreated file has the same number of pages though...

This is the code

StreamReader sr = new StreamReader(_filePath);
str = sr.ReadToEnd();
File.WriteAllText(@"C:\recreated.pdf",开发者_运维技巧 str);

what am I doing wrong?


For a start, you're using a StreamReader even though PDFs are binary data. You don't want to write text - you want to read and write binary data.

See my answer to a similar question yesterday (not exact duplicate, but similar) for more details and code.

0

精彩评论

暂无评论...
验证码 换一张
取 消