Store a file into a memory

  • Thread starter Thread starter Alex Shirley
  • Start date Start date
A

Alex Shirley

Hi

Can you help me?

I want to store a file of any description or format (from a hard disk)
into memory in VB.NET (using ASP.NET).

Then I want to use this datastructure in memory (containing the file)
to be used for the construction of a SMTP message.

What I am doing with SMTP at the moment is reading files off the hard
disk every time when constructing an attachment for a message (see
below code). This isn't very efficient in my situation, whereby many
people are being sent exactly the same attachment in different
messages. Basically I am trying to avoid multiple disk reads.

In summary then, can anybody give me any ideas on:

a) How to store a file (stored into memory) using VB.Net (inc
filename)
b) How to write out to memory and put it in a SMTP mail attachment?

I would be greatful for any pointers, documentation, or some sample
code(!). I have looked around but I am slightly confused.

Many thanks!

Alex

'---SAMPLE CODE BEGIN----

'NOTE filepath is the filepath of a file on a hard disk

Dim objMessage As New System.Web.Mail.MailMessage

'Code stripped out for simplicity

objMessage.Attachments.Add(New MailAttachment(filepath)

'Code stripped out for simplicity

SmtpMail.Send(objMessage)

'---SAMPLE CODE END----
 
Check out System.IO.MemoryStream and use that with StreamWriter. You'll
probably have to write it chunk by chunk using a StreamReader from a file
stream, but that's not too bad.

This could consume memory very quickly though... I don't know if your
monitoring a particular directory or what but depending on filesize you
could see OutOfMemoryExceptions.

HTH,
CJ
 
The issue is not about storing a file into a memory. The issue is
System.Web.Mail.MailAttachment didn't provide a method to read data from
memory. You must create your own SMTP component or use third-party SMTP
component.
 
Does Dundas ASPMail? It's a free component too. I just didn't have an
answer for that...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top