473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

ASP.NET FileUploader

31
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
Feb 5 '09 #1
3 2030
Frinavale
9,735 Expert Mod 8TB
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
Feb 5 '09 #2
rajanji
31
Here is the code that i m using :

/************************************************** ***************************/
Expand|Select|Wrap|Line Numbers
  1.         string st;
  2.         st = Server.MapPath(".");
  3.         Label24.Text = st;
  4.         string fn = FileUpload1.FileName;
  5.         if (!st.EndsWith("/") == true)
  6.         {
  7.             st += "/";
  8.         }
  9.         st += fn;
  10.         FileUpload1.PostedFile.SaveAs(st);
  11.         Label24.Text = ("file uploaded");
/************************************************** ***************************/


Expand|Select|Wrap|Line Numbers
  1.         SqlCommand selcmd = new SqlCommand("select * from regjobseeker", cn);
  2.         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+"','"+fn+"')",cn);
  3.  
  4.         SqlDataAdapter da = new SqlDataAdapter();
  5.         DataSet ds = new DataSet();
  6.         DataTable dt = new DataTable();
  7.         cn.Open();
  8.         da.SelectCommand = selcmd;
  9.         da.Fill(ds,"regjobseeker");
  10.         dt=ds.Tables["regjobseeker"];
  11.         DataRow dr=dt.NewRow();
  12.         dr[0]=txtuname.Text;
  13.         dr[1]=txtpass.Text;
  14.         dr[2] = txtconfirmpass.Text;
  15.         dr[3]=txtjname.Text;
  16.         dr[4]=txtemail.Text;
  17.         dr[5]=txtadd1.Text;
  18.         dr[6]=txtadd2.Text;
  19.         dr[7]=ddlcountry.SelectedItem;
  20.         dr[8]=ddlstate.SelectedItem;
  21.         dr[9]=ddlquali1.SelectedItem;
  22.         dr[10]=ddlpguniv.SelectedItem;
  23.         dr[11]=ddlpgyr.SelectedItem;
  24.         dr[12]=TextBox8.Text;
  25.         dr[13]=ddlquali2.SelectedItem;
  26.         dr[14]=ddlgraduniv.SelectedItem;
  27.         dr[15]=ddlgradyr.SelectedItem;
  28.         dr[16]=TextBox9.Text;
  29.         dr[17]=ddlquali3.SelectedItem;
  30.         dr[18]=ddl12brd.SelectedItem;
  31.         dr[19]=ddl12yr.SelectedItem;
  32.         dr[20]=TextBox10.Text;
  33.         dr[21]=txtrole.Text;
  34.         dr[22]=txtcurrentindustry.Text;
  35.         dr[23]=txtworkexp.Text;
  36.         dr[24]=txtcrntempl.Text;
  37.         dr[25]=txtprevempl.Text;
  38.         dr[26]= txtresumetitle.Text;
  39. //problems with the following line:
  40.         dr[27]=fn;
  41.         dt.Rows.Add(dr);
  42.         da.InsertCommand = inscmd;
  43.         da.Update(ds,"regjobseeker");
  44.         cn.Close();
  45.                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.....
Feb 6 '09 #3
Frinavale
9,735 Expert Mod 8TB
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.
Feb 6 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: M P | last post by:
Can you help me find an asp code that will upload a file from my PC to web server? Mark
3
by: Bryan Fleming | last post by:
Hello, I wrote a page that uploads a file VIA http with no problems at all. My clients are using Macs and wouldn't you know it, the site won't upload for them. Anyone seen a work-around for...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
1
by: Rizwan | last post by:
I am writing this code for file upload in asp 3.0 on my webpage........ It is working on local system but when i want to upload an image on my website from client machine it is not working ..........
0
by: RosH | last post by:
Dear All, Please find below an Inserting Event code expected to trigger just before the insert event of a FormView control. Everything works just fine but the event throws an exception that the...
5
by: Queez | last post by:
Afternoon, I've spent all morning trawling the net looking for an answer to this. In the end, I've had to resort to good old fashioned asking. How do you determine a file's MIME type using...
9
by: saldandm | last post by:
I think this is probably some minor oversight on my end but I'm just missing it. I have a multipart/form-data form in a ASP page. Inside the form I have traditional text fields and a upload field...
0
by: LoriFranklin | last post by:
I'm a bit of a newbie here. I've learned a lot from reading the posts you all have here. I need some help uploading files using an asp form. I am using some code that I found from Jacob at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.