通过email + gridview发送文档
本文关键字:文档 gridview email 通过 | 更新日期: 2023-09-27 18:15:07
我有一个gridview,看起来像
ID Filename Type
-----------------------------------------------------
Share view 1 Tiger .doc
share view 2 Lion .xls
share view 3 dog .ppt
当我点击查看时,文档将被打开,我们可以编辑它。我希望共享链接执行一些特定的功能。如果我点击分享,它应该要求输入电子邮件,并将相应的文档发送到所写的电子邮件。例如,如果我点击共享,文档是老虎,该文档应该发送到电子邮件写入。
我找到了解决方案。下面是使用的一段代码:
在gridview中,对于共享超链接我使用:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"FileName","Share.aspx?FileName={0}" ) %>'
Text="Share"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
分享。aspx页
string datalink;
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox2.Text = Request.QueryString[0];
datalink = this.TextBox2.Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
// Create the mail message
string strFrom = "abcd@gmail.com";
string strTo = TextBox1.Text;
string strCC = TextBox3.Text;
string strSubject = "Document shared";
string strMsg = " The document has been shared with you. Please check the attachment.";
string myPath = @"C:'Visual Studio 2008'Data'";
MailMessage objMailMsg = new MailMessage(strFrom, strTo);
objMailMsg.BodyEncoding = Encoding.UTF8;
objMailMsg.Subject = strSubject;
objMailMsg.Body = strMsg;
objMailMsg.CC.Add(strCC);
Attachment at = new Attachment(myPath + datalink);
objMailMsg.Attachments.Add(at);
objMailMsg.Priority = MailPriority.High;
objMailMsg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.EnableSsl = true;
smtp.Send(objMailMsg);
}
catch (Exception ex)
{
throw ex;
}
}