473,394 Members | 1,785 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,394 software developers and data experts.

FileUpload and mail sending

I'm trying to send e-mail with attachment that I take from FileUpload
control.
The problem is how to get full path of file.
For instance when I have file "C:\test.txt" FileUpload1.PostedFile.FileName
gets only "test.txt" and sending mail fails.

Can someone help?
Here's the code:

MailMessage mail = new MailMessage();
mail.From = "co*******@SPAMsystem.com";
mail.To = txtEmail.Text;
mail.Subject = "Anouncment about new Contract";
mail.Body = "Siging code is :" + txtSigningCode.Text;
mail.BodyFormat = MailFormat.Text;
mail.Attachments.Add(new MailAttachment(FileUpload2.PostedFile.FileName));
SmtpMail.Send(mail);
Feb 2 '07 #1
2 1148
You'll probably have to save the uploaded file to your filesystem and attach
the saved file. Use PostedFile.SaveAs.

"Qweertz" <qw*****@net.hrwrote in message
news:ep**********@news1.carnet.hr...
I'm trying to send e-mail with attachment that I take from FileUpload
control.
The problem is how to get full path of file.
For instance when I have file "C:\test.txt"
FileUpload1.PostedFile.FileName gets only "test.txt" and sending mail
fails.

Can someone help?
Here's the code:

MailMessage mail = new MailMessage();
mail.From = "co*******@SPAMsystem.com";
mail.To = txtEmail.Text;
mail.Subject = "Anouncment about new Contract";
mail.Body = "Siging code is :" + txtSigningCode.Text;
mail.BodyFormat = MailFormat.Text;
mail.Attachments.Add(new MailAttachment(FileUpload2.PostedFile.FileName));
SmtpMail.Send(mail);

Feb 2 '07 #2
You'll probably have to save the uploaded file to your filesystem and
attach the saved file. Use PostedFile.SaveAs.
Thanks, I'll try this way.
Feb 2 '07 #3

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

Similar topics

2
by: Islamegy® | last post by:
I'm use FormView for editing a photo gallery... I add FileUpload control to upload images to the Gallery. I'm binding my Formview to objectdatasource i tried upload images onItemInserting &...
1
by: Marko Vuksanovic | last post by:
I am trying to implement an upload progress indicator using atlas, using the following workaround: http://forums.asp.net/thread/1321664.aspx This is the code in FileUpload.apsx file is as...
12
by: Phil Z. | last post by:
After migrating an ASP.NET 1.1 application to 2.0 we were getting "Cannot access a closed file" errors when uploading. I found a number of post on the subject and have since moved from using an...
0
by: Christian Schlemmer | last post by:
If my code will run into the filesize-limit condition, the INSERT-statement will be executed. is there a way to avoid that? Protected Sub DetailsView1_RowInserting(ByVal sender As Object,...
4
by: Dave | last post by:
If you had a FileUpload control inside of a FormView...how would you use FindControl to access the FileUpload properties? Let me just say that...
4
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
I have a web page that at the click of a button must send a bunch (1000+) emails. Each email is sent individually. I have the code working fine, using Mail Message classes and smtp and all that. ...
3
by: rn5a | last post by:
The ASPX FileUpload control displays a TextBox along with a 'Browse...' Button. Setting the different properties of this control just reflects the changes in the TextBox but not the Button. For...
5
by: =?Utf-8?B?QmVydA==?= | last post by:
Hi How can you set the filename property in the asp:fileupload control? How can you persist the value of the chosen filename between postbacks? thanks B
9
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.