memorystream

Why does MemoryStream.GetBuffer() always throw?

北战南征 提交于 2019-12-01 03:00:06
The following code will always throw UnuthorizedAccessException (MemoryStream's internal buffer cannot be accessed.) byte[] buf1 = { 2, 3, 5, 7, 11 }; var ms = new MemoryStream(buf1); byte[] buf2 = ms.GetBuffer(); // exception will be thrown here This is in a plain old console app and I'm running as an admin. I can't imagine a more privileged setting I could give this code. So why can't I get at this buffer? (And if nobody can, what's the point of the GetBuffer method?) The MSDN docs say To create a MemoryStream instance with a publicly visible buffer, use MemoryStream, MemoryStream(array[],

MemoryStream, Cannot access a closed stream

我的未来我决定 提交于 2019-12-01 02:51:01
With the sharpPDF library I generate a pdf memory stream, and I want to send it directly via email. But the line ms.Seek(.... gives an ObjectDisposedException; Cannot access a closed Stream. The pdf.CreatePDF method takes either an (output) fileName string, or an (out)Stream. But I guess it also closes the stream? I'm not used to work much with streams, so if you could please advise how it should be done? The sharpPDF source code of the CreatePDF method can be found here: http://www.java2s.com/Open-Source/CSharp/PDF/SharpPDF/sharpPDF/pdfDocument.cs.htm Public Sub SendPDF() Dim pdf As New

With FileStreamResult, how is the MemoryStream closed?

懵懂的女人 提交于 2019-12-01 02:04:49
The following code works, but I'm wondering if the MemoryStream created is closed properly. How should this be performed or does FileStreamResult handle it for me? public FileStreamResult DownloadBudgetedRoleOpportunities( Guid projectGuid, IEnumerable<Guid> guidRequiredRoles) { var rolebroker = new ProjectRoleBudgetBroker(); var memstream = rolebroker.CreateBudgetedRoleOpportunies( projectGuid, guidRequiredRoles); var fsr = new FileStreamResult ( memstream, "application/csv" ) { FileDownloadName = "RoleOpportunities.csv" }; // memstream.Close(); throws exception return fsr; } The

MemoryStream, Cannot access a closed stream

筅森魡賤 提交于 2019-11-30 22:33:47
问题 With the sharpPDF library I generate a pdf memory stream, and I want to send it directly via email. But the line ms.Seek(.... gives an ObjectDisposedException; Cannot access a closed Stream. The pdf.CreatePDF method takes either an (output) fileName string, or an (out)Stream. But I guess it also closes the stream? I'm not used to work much with streams, so if you could please advise how it should be done? The sharpPDF source code of the CreatePDF method can be found here: http://www.java2s

With FileStreamResult, how is the MemoryStream closed?

故事扮演 提交于 2019-11-30 22:20:03
问题 The following code works, but I'm wondering if the MemoryStream created is closed properly. How should this be performed or does FileStreamResult handle it for me? public FileStreamResult DownloadBudgetedRoleOpportunities( Guid projectGuid, IEnumerable<Guid> guidRequiredRoles) { var rolebroker = new ProjectRoleBudgetBroker(); var memstream = rolebroker.CreateBudgetedRoleOpportunies( projectGuid, guidRequiredRoles); var fsr = new FileStreamResult ( memstream, "application/csv" ) {

wkhtmltopdf outputstream & download - diaglog

南楼画角 提交于 2019-11-30 20:49:23
is it possible to get a pdf stream created by wkhtmltopdf from any html file and popup a download dialog in IE/Firefox/Chrome etc.? At the moment I get my outputstream by this code: public class Printer { public static MemoryStream GeneratePdf(StreamReader Html, MemoryStream pdf, Size pageSize) { Process p; StreamWriter stdin; ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = @"C:\PROGRA~1\WKHTML~1\wkhtmltopdf.exe"; // run the conversion utility psi.UseShellExecute = false; psi.CreateNoWindow = true; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi

Using MemoryStream to write out to XML

会有一股神秘感。 提交于 2019-11-30 19:33:16
I have noticed two different approaches to writing out data to an XML file (error handling omitted for brevity). The first method has you build the XML document and then simply save the XML to a file: using (XmlWriter writer = XmlWriter.Create(fileName)) { writer.WriteStartDocument(true); writer.WriteStartElement("parentelement"); writer.WriteEndElement(); writer.WriteEndDocument(); } The second method has you create a MemoryStream, and then save the MemoryStream to a file: XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; MemoryStream ms = new MemoryStream(); using

How to download memorystream to a file?

白昼怎懂夜的黑 提交于 2019-11-30 12:20:12
I'm using the below sample code for writing and downloading a memory stream to a file in C#. MemoryStream memoryStream = new MemoryStream(); TextWriter textWriter = new StreamWriter(memoryStream); textWriter.WriteLine("Something"); byte[] bytesInStream = new byte[memoryStream.Length]; memoryStream.Write(bytesInStream, 0, bytesInStream.Length); memoryStream.Close(); Response.Clear(); Response.ContentType = "application/force-download"; Response.AddHeader("content-disposition", "attachment; filename=name_you_file.xls"); Response.BinaryWrite(bytesInStream); Response.End(); I am getting the

iTextSharp - Create new document as Byte[]

两盒软妹~` 提交于 2019-11-30 09:40:07
问题 Have a little method which goes to the database and retrieves a pdf document from a varbinary column and then adds data to it. I would like to add code so that if this document (company stationery ) is not found then a new blank document is created and returned. The method could either return a Byte[] or a Stream. Problem is that the variable "bytes" in the else clause is null. Any ideas what's wrong? private Byte[] GetBasePDF(Int32 AttachmentID) { Byte[] bytes = null; DataTable dt =

difference between memory stream and filestream

此生再无相见时 提交于 2019-11-30 06:18:55
问题 During the serialization we can use either memory stream or file stream. What is the basic difference between these two? What does memory stream mean? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary; namespace Serilization { class Program { static void Main(string[] args) { MemoryStream aStream = new MemoryStream(); BinaryFormatter aBinaryFormat = new BinaryFormatter(); aBinaryFormat.Serialize(aStream,