473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Store a file into a memory

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----
Nov 21 '05 #1
3 5375
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
"Alex Shirley" <po******@alexshirley.com> wrote in message
news:e9**************************@posting.google.c om...
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----

Nov 21 '05 #2
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.

"Alex Shirley" wrote:
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----

Nov 21 '05 #3
Does Dundas ASPMail? It's a free component too. I just didn't have an
answer for that...

"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
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.

"Alex Shirley" wrote:
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----

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pei_world | last post by:
hi I am new to C# programming. can anyone tell me what is the standard way to store high sensitive user data for application, so that application next run can get back those data.
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
0
by: KK | last post by:
I am testing some code after reading the following article in MSDN. "Cryptographic Hash Algorithms Let You Detect Malicious Code in ASP.NET" In my case, I have quite a lot of aspx files. So I...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
3
by: noridotjabi | last post by:
Say I'm writting a program. In this program for some reason I need to store data somewere were I will be able to access it again. I don't want to store it in a file because then it could be...
8
by: Merk | last post by:
I'm looking for a safe and maintainable way to store connection string info (connecting to SQL Server 2005 from .NET 2.0 Windows Forms client app); things like server name or IP address and...
2
by: Laszlo Nagy | last post by:
Hi, I'm working on a pivot table. I would like to write it in Python. I know, I should be doing that in C, but I would like to create a cross platform version which can deal with smaller...
3
by: M.-A. Lemburg | last post by:
On 2008-08-07 20:41, Laszlo Nagy wrote: 1 It also very fast at dumping/loading lists, tuples, dictionaries, floats, etc. -- Marc-Andre Lemburg eGenix.com
3
by: =?Utf-8?B?Sm9u?= | last post by:
Hello, I have tried to use the app.config and settings.cs files to store my data (which I want to be user changeable at runtime). I can write to (what I assume is an object in memory) and it does...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.