dev 0

dev 0

  • NA
  • 31
  • 36k

How to open a file directly from a MemoryStream opposed to writing to disk (pdf file)

Oct 17 2011 1:17 AM
Hi
 
I am doing code in C#, and i have created pdf using itextsharp,
now i want to open my pdf directly in Acrobat Reader 9 (without giving any path to filestream)and then ask to client , wheather he want to save that pdf file.
MemoryStream ms = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(pDoc, ms);
 var file = System.IO.Path.GetTempFileName();
using (var fileStream = File.OpenWrite(file))
{
var buffer = ms.GetBuffer();
fileStream.Write(buffer, 0, (int)buffer.Length);
}
 
I have used above code, but getting error SecurityException was unhandled by user code -- File operation not permitted. Access to path '' is denied
 
when i have used below code den pdf is getting created , means Admin settings have not any problems.
 writer = PdfWriter.GetInstance(doc, new FileStream(filpath, FileMode.Create));
 
so plz help me , so that i will open direct pdf from memorystream without saving it in a disk.

Answers (4)