.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

HTMLIMage and MemoryStream

Posted By:      Posted Date: October 18, 2010    Points: 0   Category :ASP.Net



I'm trying to implent a Captcha in my webSite. But all solution i find with HTTPHandler don't work (red cross)

I'm trying to create an specific object to do that but i've a problem to put my MemoryStream in a HTMLImage.


In my default page, i've placeholder.

In load :

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim MonImg As New CaptchaControl
        MonImg.MyCode = "blabla"
    End Sub


and My CaptchaControls:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO

Imports System.Drawing
Imports Microsoft.VisualBasic
Imports System.Drawing.Drawing2D

<DefaultProperty("MyCode"), ToolboxData("<{0}:CaptchaControl runat=server></{0}:CaptchaControl>")> _
Public Class CaptchaControl
    Inherits WebControl

    Dim _MyCode As String = Nothing

View Complete Post

More Related Resource Links

memorystream attachment on an email



Sorry if this is the wrong forum, couldn't find a mail or IO forum. I'm trying to attach a memorystream as an attachment to an email, however the file is always empty. I'm using a streamwriter to write the text in to the memorystream, I then flush the streamwriter and I can see the memorystream has data. However when I attach the memorystream to the email the file is always empty. I can't see what I'm doing wrong. Any help would be great. The code is:

                    System.IO.MemoryStream memorystream = new System.IO.MemoryStream();
                    System.IO.StreamWriter streamwriter = new System.IO.StreamWriter(memorystream);
                    Attachment data = new Attachment(memorystream, fName, MediaTypeNames.Application.Octet);
                    SmtpClient smtp = new SmtpClient();

var4 is a string of XML data.






.net 4.0 breaks serialization test - MemoryStream that cannot seek



I'm serializing a Dictionary<string,string> using BinaryFormatter to a class that extends MemorySteam that I call CannotSeekStream (source below).  CannotSeekStream follows the MSDN guidlines for throwing NotSupportedException from a few properties/methods.  In .net 3.5 I can serialize just fine.  In 4.0, I get a NotSupportedException from the Length property.  stacktrace is below.  At a high level, its strange that I cannot serialize to a stream that cannot seek.  Is this a bug in the framework?


at CannotSeekStream.get_Length() at System.IO.MemoryStream.set_Capacity(Int32 value) at System.IO.MemoryStream.EnsureCapacity(Int32 value) at System.IO.MemoryStream.WriteByte(Byte value) at System.IO.BinaryWriter.Write(Byte value) at System.Runtime.Serialization.Formatters.Binary.SerializationHeaderRecord.Write(__BinaryWriter sout) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteSerializedStreamHeader(Int64 topId, Int64 headerId) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStrea

usage of memorystream

when will we use memory stream?

Issue with persisting from MemoryStream in XamlPackage format


I am trying to persist some data from a rich text box to a BLOB in a database

		void TestCode2()
			TextRange range = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);

			MemoryStream mem = new MemoryStream();

			range.Save(mem, System.Windows.DataFormats.XamlPackage);

			byte[] persist = mem.GetBuffer();

			MemoryStream mem2 = new MemoryStream(persist);
				range.Load(mem2, System.Windows.DataFormats.XamlPackage);
			catch (ArgumentException ex)
				System.Diagnostics.Debug.WriteLine(string.Format("Exception {0}", ex.Message));

The code above summarizes what I am trying to do.

But the main problem is an ArgumentException is being thrown.

But if do the following everything works OK:

		void TestCode()
			TextRange range = 

Printing from a MemoryStream


Hi All,

I'm writing an image viewer user control that is fed a MemoryStream and displays the image and allows for zooming, panning etc.  Now, I need to be able to print the original document (a Tiff) from the MemoryStream.  I don't have a file and can't create files, I just have this MemoryStream.

I've seen tons of examples where files are written to a MemoryStream, but none seem to work for me if I try to pick it up from that point.

Here's the most common code I've seen:

        FlowDocument imageDoc = new FlowDocument();
        TextRange dest = new TextRange(imageDoc.ContentStart, imageDoc.ContentEnd);
        dest.Load(ImageStream, DataFormats.Xaml);
        DocumentPaginator paginator = ((IDocumentPaginatorSource)imageDoc).DocumentPaginator;
        print.PrintDocument(paginator, "doc");

 I'm not sure if I've set this up right, but it fails on the DataFormats.Xaml line:

Data at the root level is invalid. Line 1, position 1.

I've tried other formats, in particular DataFormats.Tiff, but all fail but with slightly different error messages.

It would seem that the key is to convert the MemoryStream into a FlowDocument, which then can be printed.  Maybe it would be better to convert it to a XpsDocument instead.  I'm just lost in the WPF4 sauce!


Displaying Images from MemoryStream doesn't work


hi all great guys

i want to display list of images from list of memory streams

it doesn't work  and it throws an exception too

this is my try


  public List<MemoryStream> ImagesMemoryStream
   get { return imagesMemoryStream; }
    imagesMemoryStream = value;
    foreach (MemoryStream currentImageMemoryStream in imagesMemoryStream)
     Image image = new Image();
     BitmapImage bitmapImage = new BitmapImage();
     bitmapImage.StreamSource = currentImageMemoryStream;
     bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
     bitmapImage.EndInit(); // throws an exception
     image.Source = bitmapImage;

the exception is (NotSupportedException)
No imaging component suitable to complete this operation was found.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend