memorystream

How to set the name of the file when streaming a Pdf in a browser?

谁都会走 提交于 2019-12-06 22:08:06
问题 Not sure exactly how to word this question ... so edits are welcomed! Anyway ... here goes. I am currently use Crystal Reports to generated Pdfs and just stream the output to the user. My code looks like the following: System.IO.MemoryStream stream = new System.IO.MemoryStream(); stream = (System.IO.MemoryStream)this.Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); this.Response.Clear(); this.Response.Buffer = true; this.Response.ContentType = "application

.Net MemoryStream close issue

巧了我就是萌 提交于 2019-12-06 16:11:07
For a .Net MemoryStream object instance, do I need to close it explicitly after using it? Or no need to close it? Which is the best practices? I am using VSTS2008 + .Net 3.5 + C#. you should close it when you are done with it. The best practice is to close the stream in the finally section of a try-catch-finally block. you can get more information here: http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx Better yet would be to use Using using (MemoryStream ms = /*get it using your favorite ctor*/) { // use it here // and now flush and copy to a file stream (for example) ws

MemoryStream.Position or MemoryStream.Seek does not work (Silverlight)

僤鯓⒐⒋嵵緔 提交于 2019-12-06 15:44:31
I have a memorystream in a silverlight app. I have to copy this memorystream to a filestream object. If I call: memoryStream.Position = 0; memoryStream.Seek(0,SeekOrigin.Begin); It does not work, I debug the application, check the properties of the memorystream, and the position still points to the end of the file. Any clues? Is it possible that another of your properties is being triggered in the debugger, and reading through the stream? Rather than using the debugger, what happens if you log (or show on a message box): Log("Position = " + stream.Position); stream.Position = 0; Log("Position

open byte array from memory stream in new tab or window

旧街凉风 提交于 2019-12-06 13:40:28
问题 This seems to be a common problem but after a lengthy search I have yet to find a solution that fits my needs. I am using itextsharp to fill out a pdf form from which i create a byte array. (There are multiple pages of the same form with the same information that I combine into a single pdf document). I can do this without issues, the problem is when I display the final pdf document to the user I need to open it in a different window or tab WITHOUT first prompting the user to save or open the

Sending image with byte array convertion, from java to c#

╄→尐↘猪︶ㄣ 提交于 2019-12-06 11:08:53
I am trying to send a .jpg file which is on my android device to my server computer. To do this, I am converting the picture into a byte array by a java android application, and sending it as an argument to my server computer. I`m doing this by a web service call. The first function is edited: public static byte[] ImageConvertion(){ File inputFile = new File("/storage/emulated/0/IFSpictures/icon-si_strapclamp.jpg"); byte[] data; try{ FileInputStream input = new FileInputStream(inputFile); ByteArrayOutputStream output = new ByteArrayOutputStream (); byte[] buffer = new byte[65535]; int l; while

Can a byte[] buffer for a MemoryStream have variable size?

假如想象 提交于 2019-12-06 10:05:01
I'm serializing an object to a byte[] using MemoryStream : byte[] serialized = new byte[1000]; using (MemoryStream stream = new MemoryStream(serialized)) using (TextWriter textWriter = new StreamWriter(stream)) serializer.Serialize(textWriter, stuffToSerialize); is there any way I can set 'serialized' to grow according to the size of the stuffToSerialize ? The parameterless constructor new MemoryStream() uses one. Then serialise into it, and then when you need the byte[] call ToArray() which creates a copy of whatever length of the buffer was actually used (the internal buffer will generally

How to fill a MemoryStream with 0xFF bytes?

安稳与你 提交于 2019-12-06 07:55:24
I have a MemoryStream which is created from a File at runtime. Then the MemoryStream is edited and some bytes are removed. Now I have to maintain a Constant Filesize so I have to fill the MemoryStream with 0xFF bytes.. What is the Fastest way to Do this Operation? I know, that I always can loop through the MemoryStream sizes and add 0xFF's but I need to know a faster and more efficient way to do it! If you have many bytes to write to the stream, it may be more efficient to write a array rather than each byte individually: static void Fill(this Stream stream, byte value, int count) { var buffer

C# 3.0 Save itextsharp pdf to database using MemoryStream

只谈情不闲聊 提交于 2019-12-06 07:24:07
问题 I'm trying to save to databse a pdf file generated by itextsharp. But, I haven't been successfully so far. I'm using Linq to sql. Here's the code: MemoryStream ms = new MemoryStream(); Document d = new Document(PageSize.A4, 60, 60, 40, 40); PdfWriter w = PdfWriter.GetInstance(d, ms); w.CloseStream = false; string txtTemplate = ""; Encoding en = Encoding.GetEncoding("iso-8859-1"); StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/Content/templates/CessaoDireitosDica.txt"

C# to Java: Base64String, MemoryStream, GZipStream

十年热恋 提交于 2019-12-06 03:06:53
问题 I have a Base64 string that's been gzipped in .NET and I would like to convert it back into a string in Java. I'm looking for some Java equivalents to the C# syntax, particularly: Convert.FromBase64String MemoryStream GZipStream Here's the method I'd like to convert: public static string Decompress(string zipText) { byte[] gzipBuff = Convert.FromBase64String(zipText); using (MemoryStream memstream = new MemoryStream()) { int msgLength = BitConverter.ToInt32(gzipBuff, 0); memstream.Write

create file and save to it using memorystream

丶灬走出姿态 提交于 2019-12-05 19:22:47
How can i create a file and write to it using the memory stream? I need to use the memorystream to prevent other threads from trying to access the file. The data i'm trying to save to a file is html. How can this be done? (Presuming you mean how to copy a file's content to a memory stream) If you are using framework 4: MemoryStream memoryStream = new MemoryStream(); using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read)) { fileStream.CopyTo(memoryStream); } Jayesh Sorathia Here are code to create file byte[] data = System.Text.Encoding.ASCII.GetBytes("This is a