在电子邮件+ gridview中发送文档

时间:2011-11-19 20:11:06

标签: c#

我有一个貌似的网格视图

                   ID       Filename      Type
-----------------------------------------------------
Share  view        1      Tiger           .doc
share  view        2      Lion            .xls
share  view        3      dog             .ppt

当我点击视图时,文档将被打开,我们可以编辑它。我希望共享链接执行一些特定的功能。如果我点击共享,它应该要求输入电子邮件,并将相应的文档发送到写的电子邮件。防爆。如果我点击文档为虎的共享,该文档应该发送到写的电子邮件。

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。这是一段代码。

在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>

在share.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;
        }

    }