Advertisement

05.16.2008 at 11:51PM PDT, ID: 23410315 | Points: 500
[x]
Attachment Details

getting error in  datagrid/gridview when dowloading the attachments

Asked by medapati in Programming for ASP.NET, C# Programming Language, .NET Framework 2.0

Tags: asp.net, getting error when download the attachment from datagrid while using ajax

I am using asp.net ajax,i tried this code to download the attachment from the datagrid.string strFilename1 = e.CommandArgument.ToString();
            if (strFilename1.Trim() == "JobDescriptions_10_5_2008")
            {
               
            }
            else
            {

                Response.ClearHeaders();
                Response.Clear();
                Response.AppendHeader("Content-Disposition", "attachment;Filename=" + strFilename1);
                Response.TransmitFile("Admin/JobDescriptions/" + strFilename1);
                Response.End();
            }

    But its showing error,i am sending error as attachment.please solve this problem. its urgentStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Mail;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
using System.Text;
using System.ComponentModel;
 
 
public partial class Careers : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
    public string strFileName, attach1;
    protected void Page_Load(object sender, EventArgs e)
    {
        BindCareers();
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        string StrFileName="";
        StringBuilder emailstr;
        emailstr = new StringBuilder();
        emailstr.Append("");
        emailstr.Append("<TABLE cellSpacing=2 cellPadding=2  align=center>");
        emailstr.Append("<TBODY><TR><TD bgColor=#c05974 colSpan=2>");
        emailstr.Append("</TD></TR>");
        emailstr.Append("<TR><TD>");
        emailstr.Append("<P>Name:</P>");
        emailstr.Append("</TD><TD>" + txtFrom.Text + "</TD></TR>");
        emailstr.Append("<TR><TD>");
        emailstr.Append("<P>Phone</P></TD><TD>" + txtPhone.Text + "</TD></TR>");
        emailstr.Append("<TR><TD><P>Email</P></TD>");
        emailstr.Append("<TD>" + txtEmail.Text + "</TD></TR>");
        emailstr.Append("<TR><TD bgColor=#c05974 colSpan=2><P> &nbsp;&nbsp;</P></TD></TR>");
        emailstr.Append("<TR><TD><P> &nbsp;&nbsp;</P></TD>");
        emailstr.Append("<TD>&nbsp;&nbsp;</TD></TR><TR><TD><P>Cover Letter");
        emailstr.Append("</P></TD>" + txtCover.Text + "</TD></TR>");
        emailstr.Append("<TR bgColor=#c05974><TD colSpan=2><P> &nbsp;&nbsp;</P></TD></TR></TBODY>");
        emailstr.Append("</TABLE>");
        MailMessage MyMail = new MailMessage();
        MyMail.From = txtEmail.Text;
        MyMail.To = ConfigurationSettings.AppSettings["strAdmin"].ToString();
     
        MyMail.Subject = "Career Application";
        MyMail.BodyFormat = MailFormat.Html;
        MyMail.Body = emailstr.ToString();
      
        StrFileName = fileAttachment.PostedFile.FileName;
        if (StrFileName != "") 
        {           
            StrFileName = StrFileName.Substring(StrFileName.LastIndexOf("\\") + 1);
            StrFileName = "Admin/Resumes/" + StrFileName;
            fileAttachment.PostedFile.SaveAs(Server.MapPath(StrFileName));
            MailAttachment MyAttachment = new MailAttachment(Server.MapPath(StrFileName));
            MyMail.Attachments.Add(MyAttachment);
        }
        SmtpMail.Send(MyMail);
        Response.Redirect("CareersSucess.aspx");
     
    }
    
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Control myForm = Page.FindControl("form1");
        foreach (Control ct1 in myForm.Controls)
        if (ct1.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox")) ((TextBox)ct1).Text = "";
    }
 
    public void BindCareers()
    {
        string strqueary;
        strqueary = "select CAR_ID,CAR_LOCATION,CAR_POSITION,CAR_NOOF_VACCANCIES,case when (CAR_DESCRIPTION='JobDescriptions_10_5_2008') then '&nbsp;<a href=''mailto:Sanjeev@impeloverseas.com''>Contact HR</a>' else 'Download' end as DES,CAR_DESCRIPTION from IML_CAREERS";
        SqlDataAdapter da = new SqlDataAdapter(strqueary, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            dgCarrers.DataSource = ds;
            dgCarrers.DataBind();
           
        }
        else
        {
            lblMessage.Text = "No Vacancies";
        }
        
    }
    protected void dgCarrers_ItemCommand(object source, DataGridCommandEventArgs e)
    {
 
        if (e.CommandName == "Download")
        {
 
            string strFilename1 = e.CommandArgument.ToString();
            if (strFilename1.Trim() == "JobDescriptions_10_5_2008")
            {
               
            }
            else
            {
 
                Response.ClearHeaders();
                Response.Clear();
                Response.AppendHeader("Content-Disposition", "attachment;Filename=" + strFilename1);
                Response.TransmitFile("Admin/JobDescriptions/" + strFilename1);
                Response.End();
            }
         
        }
    }
   
}
Attachments:
 
i am getting this error when i am clicking download button in datagrid
i am getting this error when i am clicking download button in datagrid
 
 
Loading Advertisement...
 
[+][-]05.17.2008 at 12:45AM PDT, ID: 21588311

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628