Web Forms :: Extract As Excel Format Then Attach To Email
Jan 5, 2010
I have this scenario where I extract the data from the database as excel format, instead of saving it some where in the drive, I want is to attach this file and send it via e-mail.
i have using sql server 2005 express managment studio, i have create my database and every thing just i want to extact Database and attach it to My asp.net 3.5 Project how?
I need to send table information as PDF file as attachment. how do i convert Div conntent into PDF. i got many link but i was unable to convert only my Div content not HTML page. is there any way to do this.
I have an aspx page (c#) that a user can upload an image file. I'd also like them to be able to attach this image file. Is it possible to attach the image file to the email then send without saving a copy of the attchment to the web server? I don't need a copy of the file, just need to attach it.
I got a following code from another thread for generating word document it seems to be working.Now I would like to know how to attach newly generated document with email.
var emailReg = /^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/;
This is my regular expression . it accepts the email such as name.name_@__domain.in How can i format my regular expression which accepts only a valid email format only. I need the email validation for above example.it is not a duplicate one.
have code on a web form -- when you hit the button "send emails", it executes this sub which reads an SQL database table and sends emails one by one -- however I get this error above -- anyway to check it and skip to the next email? Some emails in my table have name@test.co.il for example, so it seems this causes this error.
Whenever I try to export a ListView with formatting or dynamic content in the PreRender event to an Excel file, I lose all of the changes from the PreRender event. Here's the ListView code:
I've done some reading and found that RenderControl possibly ignores anything in PreRender for a control, but I'm thinking there has to be a way to get those PreRender changes in there before extracting the ListView to Excel.
The only workaround I've found so far is to copy and paste all of my preRender code into the Page_Load, and then everything looks fine in Excel. However, then I have to duplicate my code, as I still need it in the preRender event to display it on the screen properly. I don't want to maintain the code twice.
I have several images saved as binary data in the DB. How would I remove them and attach them to an email? In the table, I have the filename, description, file(binary data), and content type.
I have a form on which anyone can send me his/her information. Now i want to add 2 or 3 file upload options so that anyone from the website can send me their files along with the information. For getting information i am using this code (in button click) which works fine for me:
using System; using System.Net.Mail; using System.Text; using System.Web.UI; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; protected void btnMyButton_Click(object sender, EventArgs e) { if (Page.IsValid) { try { string enquiry = txtEnquiry.Text.Trim(); if (String.IsNullOrEmpty(enquiry)) return; string emailTitle = GetLocaleResourceString("MyTopic.EmailTitle"); string fullName = txtFullName.Text.Trim(); string email = txtEmail.Text.Trim(); string subject = string.Format("{0}. {1}", SettingManager.StoreName, emailTitle); var body = new StringBuilder(); body.AppendFormat("<hr />{0} ({1})<hr />", emailTitle, DateTime.Now.ToShortDateString()); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.FullName"), fullName); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.E-MailAddress"), email); body.Append("<br />"); body.AppendFormat("<b>{0}:</b><br /> {1}<br />", GetLocaleResourceString("MyTopic.Enquiry"), MessageManager.FormatContactUsFormText(enquiry)); var from = new MailAddress(email, fullName); var emailAccount = MessageManager.DefaultEmailAccount; string body2 = body.ToString(); //required for some SMTP servers if (SettingManager.GetSettingValueBoolean("Email.UseSystemEmailForContactUsForm")) { from = new MailAddress(emailAccount.Email, emailAccount.DisplayName); body2 = string.Format("<b>From</b>: {0} - {1}<br /><br />{2}", Server.HtmlEncode(fullName), Server.HtmlEncode(email), body2); } var to = new MailAddress(emailAccount.Email, emailAccount.DisplayName); MessageManager.InsertQueuedEmail(5, from, to, string.Empty, string.Empty, subject, body2, DateTime.UtcNow, 0, null, emailAccount.EmailAccountId); pnlResult.Visible = true; pnlRequestQuote.Visible = false; }
Now I added 3 file upload options in the page, now when i try to add code in .cs file i get errors. This is what i am trying to add (in BOLD)
protected void btnMyButton_Click(object sender, EventArgs e) { if (Page.IsValid) { try { string enquiry = txtEnquiry.Text.Trim(); if (String.IsNullOrEmpty(enquiry)) return; string emailTitle = GetLocaleResourceString("MyTopic.EmailTitle"); string fullName = txtFullName.Text.Trim(); string email = txtEmail.Text.Trim(); string subject = string.Format("{0}. {1}", SettingManager.StoreName, emailTitle); var body = new StringBuilder(); body.AppendFormat("<hr />{0} ({1})<hr />", emailTitle, DateTime.Now.ToShortDateString()); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.FullName"), fullName); body.AppendFormat("<b>{0}:</b> {1}<br />", GetLocaleResourceString("MyTopic.E-MailAddress"), email); body.Append("<br />"); body.AppendFormat("<b>{0}:</b><br /> {1}<br />", GetLocaleResourceString("MyTopic.Enquiry"), MessageManager.FormatContactUsFormText(enquiry)); //'Attach the file if (FileUpload2.HasFile) { body.Attachments.Add(new Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName)); body.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName)); body.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName)); } else { body.Attachments.Add(new Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName)); body.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName)); } var from = new MailAddress(email, fullName); var emailAccount = MessageManager.DefaultEmailAccount; string body2 = body.ToString(); //required for some SMTP servers if (SettingManager.GetSettingValueBoolean("Email.UseSystemEmailForContactUsForm")) { from = new MailAddress(emailAccount.Email, emailAccount.DisplayName); body2 = string.Format("<b>From</b>: {0} - {1}<br /><br />{2}", Server.HtmlEncode(fullName), Server.HtmlEncode(email), body2); } var to = new MailAddress(emailAccount.Email, emailAccount.DisplayName); MessageManager.InsertQueuedEmail(5, from, to, string.Empty, string.Empty, subject, body2, DateTime.UtcNow, 0, null, emailAccount.EmailAccountId); pnlResult.Visible = true; pnlRequestQuote.Visible = false; }
I get this error message:
System.Text.StringBuilder' does not contain a definition for 'Attachments' and no extension method 'Attachments' accepting a first argument of type 'System.Text.StringBuilder' could be found (are you missing a using directive or an assembly reference?)
I have a need to poll a mail server and then extract a photo that is either embedded or attached to the email message.The goal is to extract the photo and save it to a disk file. The desired functionality is much like emailing a photo from your phone to Twitter, Flickr, etc.
I have to automate a program where whenever I receive an email with header "Item Number change: Rice 2 lbs" and the message says "Price for item 10023456 has been changed to $2.99"
I would like to extract this kind of specific emails from my emails and then extract item number (100023456) and price (2.99) and store it into temporary table or session and use this information to change the value in the database. Instead of opening database manually and change the price.
I have the following code, everything works if i remove the attachment lines. But when i add them back i get the error below: we manage our files and content thru a content management system, so thats the reason for the links as they are with the "id=" copying the link into a browser works, but i need to attach the physical file to an email to send. If it cant be done then, we will have to just move the files into a folder outside of our management system.
I'm trying to extract the domain name from an email address. For example if an email address is info@mydomain.com i want to extract 'mydomain' from the string.
I have some C# code which does this:
[Code]....
This works fine - except if a user has an email address which contains a dot '.' (e.g. fname.lname@mydomain.com) then it throws the following error:
Length cannot be less than zero.Parameter name: length Line 29: int startIndex = strEmail.IndexOf("@");Line 30: int endIndex = strEmail.IndexOf(".") - startIndex;Line 31: string domain = strEmail.Substring(startIndex + 1, endIndex - 1);
The problem is the first '.' in the email address is causing it to calculate the string from the incorrect position.
Is there a way to retify this - or does anyone know of another solution to extract the domain name from an email address?
I want to send email with an image attachment but the image must not be hosted on the server. I will attach the image show it in my html e-mail (with img src...). Is it possible?
I have a string which contains html and text.If any of the text is not encapsulated by html tags then I want to encapsulate it in <P> tags however certain tags for example anchors and bold tags etc would need to remain within the string.
I manage to upload multiple files from a web form to my local drive. Say at "D:uploadedfilesamy". How do I attach all files in the directory on my email? The email without attachment is sending just fine.
It's working good, now i need 1 more thing in this, as the pdf file generated on Button click then it should get attached automatically to mail at some email address.