Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# GimmeCode
pls give me code how to upload image in asp.net using c# with code to use file uploder command
Posted 5-Feb-11 21:06pm
devasai435
Edited 13-Apr-12 0:37am
Nelek63.4K
v2
Comments
Shahriar Iqbal Chowdhury at 6-Feb-11 2:07am
   
did you tried anything?
Tadit Dash at 30-Sep-13 10:45am
   
What have you tried so far?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

protected void UploadThisFile(FileUpload upload)
{
if (upload.HasFile)
{
string theFileName = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName);
if (File.Exists(theFileName))
{
File.Delete(theFileName);
}
upload.SaveAs(theFileName);
}
}
 
protected void buttonUpload_Click(object sender, System.EventArgs e)
{
UploadThisFile(FileUpload1);
 
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Comments
Singh Dev at 25-Sep-12 2:55am
   
if u can't satisfy then i will provide running code...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi ,
 
Please refer the following Link which will provide solution to your requirement.
 
File Upload and FileTypes-Extension Check
 
Hope this will solve the requirement.
 
Regards,
Mubin
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

step1: Add Fileupload tag in your .aspx page:
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />
Step2: Now add a button for saving uploaded file
<asp:button id="Button1" runat="server" onclick="Button1_Click" text="Upload" xmlns:asp="#unknown" />
Step3: Add a folder named "Images" in your project
 
step4: The C# code for image upload is as follows
          protected void Button1_Click(Onject sender, EventArgs e)
         {
            string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string path = Server.MapPath("/Images"+FileName);
            FileUpload1.SaveAs(path);
         }
         
  Permalink  
Comments
Member 10533447 at 9-Apr-14 4:13am
   
what is path ? or describe path ?
MohanKrishna.Kota at 9-Apr-14 4:38am
   
It is just a location telling the compiler where to store the selected image
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

 
protected void Button1_Click(object sender, EventArgs e)
    {
 
        string ServerMapPath = Server.MapPath("~//images//"+FileUpload1.FileName);
        
        FileUpload1.PostedFile.SaveAs(ServerMapPath);
    }
 
 
Code Behind for button event
 
 

<asp:fileupload id="FileUpload1" runat="server" /><br />
<asp:button id="Button1" runat="server" onclick="Button1_Click" text="Upload Image:" />
 
 
Asp.net webform page
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 30 Sep 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100