I have an open PDF file.
Is it posible using c# code to save it by referencing it without any dialoge box interfering in the way?
Thanks
Rafael
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rafael ZanzooriPosted May 3, 2012, 3:19 AM
Thank you for your reply.
I forgot to mention that the file is not yet saved to the disk.
It was opened after i clicked Open in the download dialoge box.
And then i'd like to save it.
Let's say the file name is "Report.pdf" and that i want to save it on C:\.
How do i use the code you provided?
Thanks
Rafael
brunda kPosted May 2, 2012, 4:56 AM
{
dataStream.Seek(0, SeekOrigin.Begin);
FileStream fileout = File.Create("somepath/file.pdf");
const int chunk = 512;
byte[] buffer = new byte[512];
int bytesread = dataStream.Read(buffer,0,chunk);
while (bytesread == chunk)
{
HttpContext.Current.Response.OutputStream.Write(buffer, 0, chunk);
fileout.Write(buffer, 0, chunk);
bytesread = dataStream.Read(buffer, 0, chunk);
}
HttpContext.Current.Response.OutputStream.Write(buffer, 0, bytesread);
fileout.Write(buffer, 0, bytesread);
fileout.Close();
HttpContext.Current.Response.ContentType = "application/pdf";
}