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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
brunda kRank #3,804 · 389 reputationPosted May 2, 2012, 12:56 AM EDT
{
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";
}
Rafael Zanzoori3 reputationPosted May 2, 2012, 11:19 PM EDT
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