I am trying to upload some files and send as an email. I have two update panels because when I click the Menu item, it automatically refreshes the whole page and hence no file will be attached. How do I stop it?
I want my page to hold the files until I click Button3 then it can perform the function of sending the email.
I tried your method but whenever i clicked on Menu, i have a back end code that tells it to bind a dropdownlist and what happens is that it doesnt bind tht dropdownlist because somehow the updatePanel1 is blocking it from happening.
But I also have another problem.
I want to send the uploaded files as an attachment to an email.
My uploaded files are in this directory "C:\Users\user\Documents\DocuTray"
How do i get the files already selected in FileUpload1 to be added as attachment to send an email?
if (FileUpload1.HasFiles)
{
foreach (HttpPostedFile fileName in FileUpload1.PostedFiles)
{
string fileName1 = fileName.FileName.ToString();
mM.Attachments.Add(new Attachment(fileName1));
}
}
I want to send the uploaded files as an attachment to an email.
Hi,
Thanks for your back.
For attaching email a file dirrectly from the FileUpload control, please chec below code.
private bool SendMail()
{
try
{
/* Create a new blank MailMessage */
MailMessage mailMessage = new MailMessage();
mailMessage.From = txtTo.Text;
mailMessage.To = "your email";
mailMessage.Subject = txtSubject.Text ;
msgMail.Body = txtMessage.Text ;
/* We use the following variables to keep track of
attachments and after we can delete them */
string attach1 = null;
/*strFileName has a attachment file name for attachment process. */
string strFileName = null;
if (FileUpload1.PostedFile != null)
{
/* Get a reference to PostedFile object */
HttpPostedFile attFile = FileUpload1.PostedFile;
/* Get size of the file */
int attachFileLength = attFile.ContentLength;
/* Make sure the size of the file is > 0 */
if (attachFileLength > 0)
{
/* Get the file name */
strFileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
/* Save the file on the server */
FileUpload1.PostedFile.SaveAs(Server.MapPath(strFileName));
/* Create the email attachment with the uploaded file */
MailAttachment attach = new MailAttachment(Server.MapPath(strFileName));
/* Attach the newly created email attachment */
mailMessage.Attachments.Add(attach);
/* Store the attach filename so we can delete it later */
attach1 = strFileName;
}
/* Set the SMTP server and send the email with attachment */
SmtpMail.SmtpServer = ("your smtp");
SmtpMail.Send(mailMessage);
/* Delete the attachements if any */
if (attach1 != null)
{
File.Delete(Server.MapPath(attach1));
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
protected void btn_Send_Click(object sender, EventArgs e)
{
bool TrueOrFalse = SendMail();
if ((TrueOrFalse == true))
{
Response.Redirect("~/MailSent.aspx");
}
else
{
Label1.Text = "Try again";
}
}
There is example for this, please follow below article.
I have a table Folder of which FolderID is an identity column but I deleted a row and now if i add a new row via C# using my TableAdapter, the row numbers jump. e.g i have FolderID (1,2,3,4,5,8,9...).
How Do I reset or ensure that the numbers continue in the right format in the event I delete a row i want it to be (1,2,3,4,5,6) etc. I read places that said i should try reseeding the value but cant find how to do that in Visual Studio 2012.
EDMSDataSetTableAdapters.FoldersTableAdapter folderTable = new EDMSDataSetTableAdapters.FoldersTableAdapter();
folderTable.InsertQuery1(clientname, deptvalue);
This is my insert query to add to my Folders table.
Member
1 Points
29 Posts
Updating Specific Panel in an ASPX file
Mar 19, 2014 05:07 AM|boyfunky|LINK
I am trying to upload some files and send as an email. I have two update panels because when I click the Menu item, it automatically refreshes the whole page and hence no file will be attached. How do I stop it?
I want my page to hold the files until I click Button3 then it can perform the function of sending the email.
Attached is my code
All-Star
15186 Points
3888 Posts
Re: Updating Specific Panel in an ASPX file
Mar 19, 2014 07:27 AM|raju dasa|LINK
Hi,
i think, File uploads not works with partial postbacks (update panels), it requires full postback.
You can try converting your file (stream) into base64 string and save it into custom viewstate.
that way u can persist data until ur desired event.
rajudasa.blogspot.com || rajudasa-tech
Member
1 Points
29 Posts
Re: Updating Specific Panel in an ASPX file
Mar 19, 2014 12:31 PM|boyfunky|LINK
Hi raju,
I do not understand what you mean by converting file stream into base64.
All-Star
30411 Points
3628 Posts
Re: Updating Specific Panel in an ASPX file
Mar 20, 2014 03:21 AM|Fuxiang Zhang - MSFT|LINK
Hi boyfunky,
Thank you post the issue to our forum.
Based on your description, I see you want to maintain the UploadFile when the updatepanel do a partial postback.
With your code provided, I see you have two updatepanels in your page, when a updatepanel do a partial postback.
The other one will also be refreshed, that because the UpdatePanel UpdateMode is "Always" defaultly.
So we should set the UpdatePanel UpdateMode as "Conditional" which contains the UploadFile control like below.
code behind:
Hope that helps, thanks.
Best Regards!
Member
1 Points
29 Posts
Re: Updating Specific Panel in an ASPX file
Mar 21, 2014 01:16 AM|boyfunky|LINK
Hi fuxiang,
I tried your method but whenever i clicked on Menu, i have a back end code that tells it to bind a dropdownlist and what happens is that it doesnt bind tht dropdownlist because somehow the updatePanel1 is blocking it from happening.
But I also have another problem.
I want to send the uploaded files as an attachment to an email.
My uploaded files are in this directory "C:\Users\user\Documents\DocuTray"
How do i get the files already selected in FileUpload1 to be added as attachment to send an email?
All-Star
30411 Points
3628 Posts
Re: Updating Specific Panel in an ASPX file
Mar 23, 2014 09:51 AM|Fuxiang Zhang - MSFT|LINK
Hi,
Thanks for your back.
For attaching email a file dirrectly from the FileUpload control, please chec below code.
There is example for this, please follow below article.
http://www.codedigest.com/Articles/ASPNET/374_Send_Email_with_Attachment_directly_from_FileUpload_control_in_ASPNet.aspx
Thanks.
Best Regards!
All-Star
48393 Points
12161 Posts
Re: Updating Specific Panel in an ASPX file
Mar 24, 2014 12:02 AM|chetan.sarode|LINK
http://forums.asp.net/t/1840940.aspx?Master+page+with+menu+refreshes+whole+page+
Team Lead, Product Development
Approva Systems Pvt Ltd, Pune, India.
Member
1 Points
29 Posts
Re: Updating Specific Panel in an ASPX file
Mar 25, 2014 12:07 PM|boyfunky|LINK
Hi, Fuxiang,
I get this error warning message
'System.Web.Mail.SmtpMail' is obsolete: '"The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202"'
Cant we use System.Net.Mail namespace instead of System.Web.Mail namespace?
Thanks
Kingsley
All-Star
30411 Points
3628 Posts
Re: Updating Specific Panel in an ASPX file
Mar 25, 2014 09:29 PM|Fuxiang Zhang - MSFT|LINK
Hi boyfunky,
Thanks for your response.
Classes in this System.Web.Mailhave been deprecated. Please use the System.Net.Mail namespace instead.
http://msdn.microsoft.com/en-us/library/System.Web.Mail(v=vs.110).aspx
The System.Net.Mail namespace contains classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.
For how to use the System.Net.Mail, you can refer to below article.
http://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx
Hope that helps, thanks.
Best Regards!
Member
1 Points
29 Posts
Re: Updating Specific Panel in an ASPX file
Mar 27, 2014 03:33 PM|boyfunky|LINK
Dear Fuxiang,
Are you good with SQL?
I have a table Folder of which FolderID is an identity column but I deleted a row and now if i add a new row via C# using my TableAdapter, the row numbers jump. e.g i have FolderID (1,2,3,4,5,8,9...).
How Do I reset or ensure that the numbers continue in the right format in the event I delete a row i want it to be (1,2,3,4,5,6) etc. I read places that said i should try reseeding the value but cant find how to do that in Visual Studio 2012.
This is my insert query to add to my Folders table.
Thanks
C#.net sql IdentityColumn vs2012