using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.IO; using System.Configuration; public partial class candidate_details_no_BL : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CandidateDetails(); } } protected void CandidateDetails() { try { SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=FirmusTraining; Integrated Security = True;"); con.Open(); SqlCommand cmd = new SqlCommand("Select * from candidate_details", con); SqlDataAdapter da = new SqlDataAdapter(cmd);// bridge between db and ds DataSet ds = new DataSet(); da.Fill(ds);// filling values of da in ds if (ds.Tables[0].Rows.Count > 0) { gvD.DataSource = ds; gvD.DataBind(); } else { ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());//new row cr(auto generate) adding it in ds tables gvD.DataSource = ds;//assign columns// ds putting in gridview gvD.DataBind();// values bind int columncount = gvD.Rows[0].Cells.Count;//intitialzing and declaring column1 gvD.Rows[0].Cells.Clear();//clearing the junk values2 gvD.Rows[0].Cells.Add(new TableCell());//now add the table in gv3 gvD.Rows[0].Cells[0].ColumnSpan = columncount;// gv's column, columnspan is columncount 4 gvD.Rows[0].Cells[0].Text = "No Records Found";// no details found when no records entered5 } } catch (Exception exp) { } } protected void lnkDownload_Click(object sender, EventArgs e) { LinkButton lnkbtn = sender as LinkButton; GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow; string filepath = gvD.DataKeys[gvrow.RowIndex].Value.ToString();//6 Response.ContentType = "resume/text"; Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filepath + "\"");//7 //Response.TransmitFile(Server.MapPath(filepath)); Response.TransmitFile(Server.MapPath("resume/" + filepath));//8 Response.End(); } protected void SaveCandidateDetails(object sender, EventArgs e)// fileupload { try { string filepath = Path.GetFileName(fleUploadResume.PostedFile.FileName);//9 string name = txtCandidateName.Text; string Qualification = txtQualification.Text; string SkillSet = txtSkill.Text; fleUploadResume.SaveAs(Server.MapPath("resume/" + filepath)); SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());//10 con1.Open(); SqlCommand cmd = new SqlCommand("insert into candidate_details(Name,Qualification,Skillset,filepath) values('" + txtCandidateName.Text + "','" + txtQualification.Text + "','" + txtSkill.Text + "','" + filepath + "')", con1); cmd.Parameters.AddWithValue("@Name", name); cmd.Parameters.AddWithValue("@Qualification", Qualification); cmd.Parameters.AddWithValue("@Skillset", SkillSet); cmd.Parameters.AddWithValue("@fleUploadResume", filepath); cmd.ExecuteNonQuery(); con1.Close(); } catch (Exception ex) { } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="candidate_details_no_BL.aspx.cs" Inherits="candidate_details_no_BL" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table class="style1"> <tr> <td> <asp:Label ID="Label1" runat="server" Text="Candidate Name"></asp:Label> </td> <td> <asp:TextBox ID="txtCandidateName" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label2" runat="server" Text="Candidate Qualification"></asp:Label> </td> <td> <asp:TextBox ID="txtQualification" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label3" runat="server" Text="Candidate Skillset"></asp:Label> </td> <td> <asp:TextBox ID="txtSkill" runat="server"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label4" runat="server" Text="Resume"></asp:Label> </td> <td> <asp:FileUpload ID="fleUploadResume" runat="server" /> </td> </tr> <tr> <td colspan="2" style="text-align: center"> <asp:Button ID="Submit" runat="server" Text=" Submit " OnClick="SaveCandidateDetails" /> </td> </tr> <tr> <td colspan="2" style="text-align: center"> <asp:Label ID="Label5" runat="server" Style="text-align: center" Text="Candidate Details"></asp:Label> </td> </tr> <tr> <td colspan="2"> <div> <asp:GridView runat="server" ID="gvD" AutoGenerateColumns="False" CssClass="gvD" HeaderStyle-BackColor="#61A6F8" Width="226px" CellPadding="4" ForeColor="#333333" GridLines="None" DataKeyNames="Filepath"> <AlternatingRowStyle BackColor="White" /> <Columns> <asp:BoundField DataField="Name" HeaderText="Candidate Name" /> <asp:BoundField DataField="Qualification" HeaderText="Qualification" /> <asp:BoundField DataField="skillset" HeaderText="SkillSet" /> <asp:TemplateField HeaderText="FilePath"> <ItemTemplate> <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="lnkDownload_Click"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"></HeaderStyle> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView> </div> </td> </tr> </table> </div> </form> </body> </html>
SqlCommand cmd = new SqlCommand("insert into candidate_details(Name,Qualification,Skillset,filepath) values(@Name,@Qualification,@Skillset,@filepath)", con1);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)