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 20:06pm
devasai435
Edited 12-Apr-12 23:37pm
Nelek42.1K
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 372
1 OriginalGriff 295
2 thatraja 215
3 Emre Ataseven 155
4 Shai Vashdi 125
0 Sergey Alexandrovich Kryukov 8,849
1 OriginalGriff 5,035
2 Peter Leow 3,949
3 Maciej Los 3,535
4 Abhinav S 3,148


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