By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

System.Web.Mail.MailMessage attachment problem

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.