Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Upload files, multiple files and displaying url address and multiples files have to be store in a specific folder..
XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Multiple files.aspx.cs" Inherits="Multiple_files" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td><asp:FileUpload ID="fileupload1" runat="server" /></td>

            </tr>
            <tr>
                <td><asp:FileUpload ID="fileupload2" runat="server" /></td>

            </tr>
            <tr>
                <td><asp:FileUpload ID="fileupload3" runat="server" /></td>

            </tr>
            <tr>
                <td><asp:Button ID="btnuploadall" Text="Upload All" runat="server"
                        onclick="btnuploadall_Click" /></td>
                        <td><asp:Label ID="label1" runat="server"></asp:Label></td>
                        <td><asp:Label ID="label2" runat="server"></asp:Label></td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

<pre lang="msil">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Multiple_files : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnuploadall_Click(object sender, EventArgs e)
    {
      //  string serverFilePath = UpLoad();
      //public string MultipleUpLoad(HttpPostedFile selectedFile,int ID,string type)
     // {

         string Filepath=null;
       Filepath= Server.MapPath(@"~\");

        HttpFileCollection uploadedFiles = Request.Files;

        for (int i = 0; i < uploadedFiles.Count; i++)
        {
            HttpPostedFile userPostedFile = uploadedFiles[i];
            UpLoad1(userPostedFile);

        }

    }
    public string UpLoad1(HttpPostedFile fileToUpload)
    {
        string FilePath = null;
        string Multiplefiles = null;
        //string[] a = new string[1];

        if (fileToUpload.FileName.Length > 0)
        {
            FilePath = Server.MapPath(@"~\");
            try
            {

                string files;
                string[] UR = fileToUpload.FileName.Split('\\');
               //string s2 = (@"\" + fileToUpload.FileName.Split('\\')[UR.Length - 1]);
               files= fileToUpload.FileName.Split('\\')[UR.Length - 1];
               string s1 = FilePath + files;
                fileToUpload.SaveAs(s1);
                //fileToUpload.SaveAs(s2);
                string s = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + files;
                if (s.Length == 0)
                    label1.Text += "error"+"\n";
                else
                    label1.Text += s+ "\n" ;

                if (FilePath.Length > 0)
                {
                    Multiplefiles = Server.MapPath(@"~\MultipleFiles");
                    string s2 = Multiplefiles+ @"\" + files;
                    fileToUpload.SaveAs(s2);
                   // string s2 = //Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/MultipleFiles") + files;
                    if (s1.Length == 0)
                        label2.Text += "Error" + "\n";
                    else
                        return "";//label2.Text += "Uploaded Successfully";

                }
             }

            catch
            {

            }

        }

        return "";
    }

}

Posted
Comments
kishore1215 19-Jul-11 6:56am    
vERY GOOD,KEEP IT UP.........
SruthiGeejula 19-Jul-11 6:59am    
I think its easy for u..

1 solution

My second "Google it" answer of the day - upload multiple files asp.net[^]. most of the examples show saving files on a location on a server. You can filter the search for more specific requirements.
 
Share this answer
 
Comments
Ankur\m/ 19-Jul-11 6:03am    
And yes, I hope you will learn how search engines are developers best friend. Please do use them before you come up and ask questions here.
TweakBird 19-Jul-11 6:04am    
Agreed. well said. my 5!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900