If you're saying the file is saved successfully but Adobe Reader is throwing an error it's probably because you're not actually copying the file correctly. If you look here:
var byteData = Encoding.UTF8.GetBytes(Calfilename);
using (var saveFileDialogStream = sfd.OpenFile())
{
saveFileDialogStream.Write(byteData, 0, byteData.Length);
}
The value of
byteData
here isn't the contents of the file,
Encoding.UTF8.GetBytes()
converts whatever value is passed into it into a byte array, it
doesn't read the contents of the file.
Instead you need to use the variables you've instantiated in the code. I assume that
targetPath
is where the files are stored, and
Calfilename
is the name of the file, so to get the file contents you can do:
var byteData = File.ReadAllBytes(targetPath + Calfilename);