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
Nelek49.7K
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 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
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

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

  Print Answers RSS
0 thatraja 395
1 Sergey Alexandrovich Kryukov 295
2 Gihan Liyanage 261
3 kbrandwijk 204
4 CPallini 190
0 OriginalGriff 793
1 Sergey Alexandrovich Kryukov 604
2 Dnyaneshwar@Pune 604
3 Kornfeld Eliyahu Peter 530
4 thatraja 440


Advertise | Privacy | Mobile
Web01 | 2.8.140902.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