ASP.NET FileUploader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajanji
    New Member
    • May 2008
    • 31

    ASP.NET FileUploader

    Hi all,

    How to insert & retreive an uploaded document using asp.net fileupload into sqlserver.

    I am practicing on a job portal website......

    Jobseeker uses fileupload to upload his/her resume....

    and when uses preview resume......... . the resume should be displayed here only when uses preview resume command.....


    So how to do that....


    Thanks for your help and supoort........


    Regards,

    Rajan Arora
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    It's wonderful that you want to be able to upload a file and then preview it.
    What have you tried so far to implement the solution? What problems are you having with that implementation?

    Have you looked into how to use the FileUpload Class?

    Once you have the file uploaded to the server you're probably going to want to store in such a way that it is related to the user's profile....so that you can indicate that it belongs to that person. Either store the path to the file in the user's profile, or store the file directly into the database. That way, when the user wants to preview their document you are can retrieve their document.

    -Frinny

    Comment

    • rajanji
      New Member
      • May 2008
      • 31

      #3
      Here is the code that i m using :

      /*************** *************** *************** *************** *************** **/
      Code:
              string st;
              st = Server.MapPath(".");
              Label24.Text = st;
              string fn = FileUpload1.FileName;
              if (!st.EndsWith("/") == true)
              {
                  st += "/";
              }
              st += fn;
              FileUpload1.PostedFile.SaveAs(st);
              Label24.Text = ("file uploaded");
      /*************** *************** *************** *************** *************** **/


      Code:
              SqlCommand selcmd = new SqlCommand("select * from regjobseeker", cn);
              SqlCommand inscmd=new SqlCommand("insert into regjobseeker values ('"+txtuname.Text+"','"+txtpass.Text+"','"+txtconfirmpass.Text+"','"+txtjname.Text+"','"+txtemail.Text+"','"+txtadd1.Text+"','"+txtadd2.Text+"','"+ddlcountry.SelectedItem+"','"+ddlstate.SelectedItem+"','"+ddlquali1.SelectedItem+"','"+ddlpguniv.SelectedItem+"','"+ddlpgyr.Text+"','"+TextBox8.Text+"','"+ddlquali2.SelectedItem+"','"+ddlgraduniv.SelectedItem+"','"+ddlgradyr.Text+"','"+TextBox9.Text+"','"+ddlquali3.SelectedItem+"','"+ddl12brd.SelectedItem+"','"+ddl12yr.SelectedItem+"','"+TextBox10.Text+"','"+txtrole.Text+"','"+txtcurrentindustry.Text+"','"+txtworkexp.Text+"','"+txtcrntempl.Text+"','"+txtprevempl.Text+"','"+txtresumetitle.Text+"','[B][U]"+fn+"'[/U][/B])",cn);
      
              SqlDataAdapter da = new SqlDataAdapter();
              DataSet ds = new DataSet();
              DataTable dt = new DataTable();
              cn.Open();
              da.SelectCommand = selcmd;
              da.Fill(ds,"regjobseeker");
              dt=ds.Tables["regjobseeker"];
              DataRow dr=dt.NewRow();
              dr[0]=txtuname.Text;
              dr[1]=txtpass.Text;
              dr[2] = txtconfirmpass.Text;
              dr[3]=txtjname.Text;
              dr[4]=txtemail.Text;
              dr[5]=txtadd1.Text;
              dr[6]=txtadd2.Text;
              dr[7]=ddlcountry.SelectedItem;
              dr[8]=ddlstate.SelectedItem;
              dr[9]=ddlquali1.SelectedItem;
              dr[10]=ddlpguniv.SelectedItem;
              dr[11]=ddlpgyr.SelectedItem;
              dr[12]=TextBox8.Text;
              dr[13]=ddlquali2.SelectedItem;
              dr[14]=ddlgraduniv.SelectedItem;
              dr[15]=ddlgradyr.SelectedItem;
              dr[16]=TextBox9.Text;
              dr[17]=ddlquali3.SelectedItem;
              dr[18]=ddl12brd.SelectedItem;
              dr[19]=ddl12yr.SelectedItem;
              dr[20]=TextBox10.Text;
              dr[21]=txtrole.Text;
              dr[22]=txtcurrentindustry.Text;
              dr[23]=txtworkexp.Text;
              dr[24]=txtcrntempl.Text;
              dr[25]=txtprevempl.Text;
              dr[26]= txtresumetitle.Text;
      //problems with the following line:
              dr[27]=fn;
              dt.Rows.Add(dr);
              da.InsertCommand = inscmd;
              da.Update(ds,"regjobseeker");
              cn.Close();
                     MultiView1.SetActiveView(View2);

      *************** *************** *************** *************** *************** ********

      But it is only storing the file name rather i want the .doc file to be stored directly in to the sql database and be retreieved from there only.....

      Thanks for your kind support and help.....

      Regards,

      Rajan Arora.....
      Last edited by Frinavale; Feb 6 '09, 02:07 PM. Reason: added [code] tags

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Your variable "fn" contains the file name and that's why it's only storing the file name.
        After you save the file, use the File Class load it into your program and save that into your database.

        Comment

        Working...