|
<< Click to Display Table of Contents >> FileUpload - múltiplos arquivos - sem ajax |
![]() ![]()
|
Tela
Repouso:
![]()
Após pressionar o primeiro botão e escolher 10 arquivos:
![]()
Modo de upload:

Concluído:

aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function subir() {
document.getElementById('div_botao').style.display = "none";
document.getElementById('div_aguarde').style.display = "inherit";
}
</script>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div>
<input type="file" id="myfile" multiple="multiple" name="myfile" runat="server" size="100" />
<br />
<div id="div_botao" style="display: inherit">
<asp:Button ID="Button1" CssClass="botao" runat="server" Text="Upload!" OnClick="Button1_Click" OnClientClick="subir()" />
<br />
</div>
<div id="div_aguarde" style="display: none">
<asp:Label ID="lblMsg" runat="server" Text="Um momento..."></asp:Label>
<asp:Image ID="ImgCarregando" runat="server" ImageUrl="http://www.ceunes.ufes.br/intranetnova/imagens/processing.gif" />
</div>
<asp:Label ID="Span1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
cs
using System;
using System.IO;
using System.Web;
namespace WebApplication3
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string filepath = Server.MapPath("\\Upload");
HttpFileCollection uploadedFiles = Request.Files;
Span1.Text = string.Empty;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
Span1.Text += "<u>File #" + (i + 1) + "</u><br>";
Span1.Text += "File Content Type: " + userPostedFile.ContentType + "<br>";
Span1.Text += "File Size: " + userPostedFile.ContentLength + "kb<br>";
Span1.Text += "File Name: " + userPostedFile.FileName + "<br>";
userPostedFile.SaveAs(filepath + "\\" + Path.GetFileName(userPostedFile.FileName));
Span1.Text += "Location where saved: " + filepath + "\\" + Path.GetFileName(userPostedFile.FileName) + "<p>";
}
}
catch (Exception Ex)
{
Span1.Text += "Error: <br>" + Ex.Message;
}
}
}
}
}
Projeto

Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="80192"/>
</system.web>
</configuration>