LIKE US ON FACE BOOK

Friday, 22 February 2013

Uploading Single/Multiple Files in ASP.Net without using any Plug-in or Jquery

Here is most simplest way i found while working on .....
U guys no need to google further..I bet it..

create a file called Filename.aspx.cs 

write a this code 


<div>
        <input type="file" id="FileUpload1" multiple="multiple" runat="server"/>

        <asp:Button runat="server" ID="btnupload" Text="Upload"
            onclick="btnupload_Click"/>&nbsp;<br/>

        <asp:Label runat="server" ID="Label1"></asp:Label> 
</div>

Filename.aspx.cs

protected void btnupload_Click(object sender, EventArgs e)
    {
      string tempPath =          System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
       string savepath = Server.MapPath(tempPath);
        for(int i=0;i<Request.Files.Count;i++)
        {            
            HttpPostedFile hpf = Request.Files[i];
            string filename = hpf.FileName;
            hpf.SaveAs(savepath + @"\" + filename);
        }

    } 
Web.config

<appSettings>
    <add key ="FolderPath" value ="uploads"/>
</appSettings > 

Any Doubts regarding this please do ask...

No comments:

Post a Comment