I am creating a PDF file on android device and trying to write it. However the created file says "not an valid pdf" when I try to open. I get exception in code if I try to write/open.
error:
Unhandled Exception: 10-25 18:51:32.853 E/mono-rt (21231): [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Sharing violation on path /sdcard/Download/test5.pdf".
But the file is created in the path. I tried opening manually and got error that the file is not valid.
I am using Xamarin.Android.
Code:
String filePath;
FileStream fs;
filePath = Path.Combine("sdcard/Download/", "test5.pdf");
fs = new FileStream(filePath, FileMode.Create);
var pdfBinary = Convert.FromBase64String(buf);
using (var writer = new BinaryWriter(fs)) {
writer.Write(pdfBinary, 0, pdfBinary.Length);
writer.Close();
}