468,247 Members | 1,440 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

System.Web.Mail.MailMessage attachment problem

Hi, all!

I'm trying to use the System.Web.Mail. "package" combinded
with System.Web.Mail.SmtpMail in order to send MS Excel
spreadsheets attached to mail messages. However, sending
one single spreadsheet attachment per message, seems to be
causing som kind of corruption of the attachment, while
several spreadsheets per works just fine. Consider the
following three snippets of C# code:

// Sample 1 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);
// Sample 2 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);

// Sample 3 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);
Using the code in Sample 1, both attatchments can be
opened by Excel without any problem, as they arrive at the
receiving end.

Using the code in Sample 2 or Sample 3, however, NEITHER
of the attachments, which happens to be the EXACT same two
Excel spreadsheets as in Sample1, can be opened by the
receipient using Excel. Any ettemt two open them results
in either a "The document is corrupt and cannot be opened.
To try an repair..." error message or a " cannot
be accessed. The file may be read-only, or..." error
message. If any of you have an idea what's causing this
problem, and maybe even a suggestion for a workaround,
your reply would be highly appreciated.

Regards, Trond

Nov 15 '05 #1
4 8119
Try to use encoding parameter in MailAttachment constructor.
"Trond A. S. Andersen" <ts*@scandpower.no> wrote in message
news:08****************************@phx.gbl...
Hi, all!

I'm trying to use the System.Web.Mail. "package" combinded
with System.Web.Mail.SmtpMail in order to send MS Excel
spreadsheets attached to mail messages. However, sending
one single spreadsheet attachment per message, seems to be
causing som kind of corruption of the attachment, while
several spreadsheets per works just fine. Consider the
following three snippets of C# code:

// Sample 1 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);
// Sample 2 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);

// Sample 3 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);
Using the code in Sample 1, both attatchments can be
opened by Excel without any problem, as they arrive at the
receiving end.

Using the code in Sample 2 or Sample 3, however, NEITHER
of the attachments, which happens to be the EXACT same two
Excel spreadsheets as in Sample1, can be opened by the
receipient using Excel. Any ettemt two open them results
in either a "The document is corrupt and cannot be opened.
To try an repair..." error message or a " cannot
be accessed. The file may be read-only, or..." error
message. If any of you have an idea what's causing this
problem, and maybe even a suggestion for a workaround,
your reply would be highly appreciated.

Regards, Trond

Nov 15 '05 #2
Try to use encoding parameter in MailAttachment constructor.
"Trond A. S. Andersen" <ts*@scandpower.no> wrote in message
news:08****************************@phx.gbl...
Hi, all!

I'm trying to use the System.Web.Mail. "package" combinded
with System.Web.Mail.SmtpMail in order to send MS Excel
spreadsheets attached to mail messages. However, sending
one single spreadsheet attachment per message, seems to be
causing som kind of corruption of the attachment, while
several spreadsheets per works just fine. Consider the
following three snippets of C# code:

// Sample 1 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);
// Sample 2 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);

// Sample 3 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server";
System.Web.Mail.SmtpMail.Send(msg);
Using the code in Sample 1, both attatchments can be
opened by Excel without any problem, as they arrive at the
receiving end.

Using the code in Sample 2 or Sample 3, however, NEITHER
of the attachments, which happens to be the EXACT same two
Excel spreadsheets as in Sample1, can be opened by the
receipient using Excel. Any ettemt two open them results
in either a "The document is corrupt and cannot be opened.
To try an repair..." error message or a " cannot
be accessed. The file may be read-only, or..." error
message. If any of you have an idea what's causing this
problem, and maybe even a suggestion for a workaround,
your reply would be highly appreciated.

Regards, Trond

Nov 15 '05 #3
Tried that. Excel spreadsheet attachments somehow
corrupted by the System.Web.Mail/System.Web.Mail.SmtpMail
framework, no matter what encoding parameter i use.

Thanks, anyway
-----Original Message-----
Try to use encoding parameter in MailAttachment constructor.

"Trond A. S. Andersen" <ts*@scandpower.no> wrote in messagenews:08****************************@phx.gbl...
Hi, all!

I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel
spreadsheets attached to mail messages. However, sending
one single spreadsheet attachment per message, seems to be causing som kind of corruption of the attachment, while
several spreadsheets per works just fine. Consider the
following three snippets of C# code:

// Sample 1 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server"; System.Web.Mail.SmtpMail.Send(msg);
// Sample 2 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server"; System.Web.Mail.SmtpMail.Send(msg);

// Sample 3 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server"; System.Web.Mail.SmtpMail.Send(msg);
Using the code in Sample 1, both attatchments can be
opened by Excel without any problem, as they arrive at the receiving end.

Using the code in Sample 2 or Sample 3, however, NEITHER
of the attachments, which happens to be the EXACT same two Excel spreadsheets as in Sample1, can be opened by the
receipient using Excel. Any ettemt two open them results
in either a "The document is corrupt and cannot be opened. To try an repair..." error message or a " cannot
be accessed. The file may be read-only, or..." error
message. If any of you have an idea what's causing this
problem, and maybe even a suggestion for a workaround,
your reply would be highly appreciated.

Regards, Trond

.

Nov 15 '05 #4
Tried that. Excel spreadsheet attachments somehow
corrupted by the System.Web.Mail/System.Web.Mail.SmtpMail
framework, no matter what encoding parameter i use.

Thanks, anyway
-----Original Message-----
Try to use encoding parameter in MailAttachment constructor.

"Trond A. S. Andersen" <ts*@scandpower.no> wrote in messagenews:08****************************@phx.gbl...
Hi, all!

I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel
spreadsheets attached to mail messages. However, sending
one single spreadsheet attachment per message, seems to be causing som kind of corruption of the attachment, while
several spreadsheets per works just fine. Consider the
following three snippets of C# code:

// Sample 1 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server"; System.Web.Mail.SmtpMail.Send(msg);
// Sample 2 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server"; System.Web.Mail.SmtpMail.Send(msg);

// Sample 3 ->

System.Web.Mail.MailMessage msg = new
System.Web.Mail.MailMessage();
msg.Attachments.Add(new System.Web.Mail.MailAttachment
("some_other_spreadsheet.xls"));

msg.From = "me@mydomain.com;
msg.To = "so*****@somewhere.com";
msg.Subject = "TWO Excel spreadsheets attached;

System.Web.Mail.SmtpMail.SmtpServer = "some_smtp_server"; System.Web.Mail.SmtpMail.Send(msg);
Using the code in Sample 1, both attatchments can be
opened by Excel without any problem, as they arrive at the receiving end.

Using the code in Sample 2 or Sample 3, however, NEITHER
of the attachments, which happens to be the EXACT same two Excel spreadsheets as in Sample1, can be opened by the
receipient using Excel. Any ettemt two open them results
in either a "The document is corrupt and cannot be opened. To try an repair..." error message or a " cannot
be accessed. The file may be read-only, or..." error
message. If any of you have an idea what's causing this
problem, and maybe even a suggestion for a workaround,
your reply would be highly appreciated.

Regards, Trond

.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Trond A. S. Andersen | last post: by
5 posts views Thread by Chris Thunell | last post: by
3 posts views Thread by Brian Farnhill (MCP VB.NET) | last post: by
1 post views Thread by theWizard1 | last post: by
4 posts views Thread by David C | last post: by
5 posts views Thread by =?Utf-8?B?SmltSm9i?= | last post: by
11 posts views Thread by Ed Bitzer | last post: by
2 posts views Thread by Prefers Golfing | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.