I'm developing a module to send emails, and one of the features is to upload multiple files...
I used this as a reference to create it: http://www.dotnetcurry.com/ShowArticle.aspx?ID=68
I also had to add jquery to allow it to upload multiple files.
<script src="Scripts/jquery-1.3.2.js" type="text/javascript">
</script>
<script src="Scripts/jquery.MultiFile.js" type="text/javascript">
</script>
However, if I upload a file that is larger than 10MB when I press a button in my form (I guess it happens whenever a postback occurs), the browser cannot load the page. So what I want is to trigger this function in my button:
protected void imgBtnEnviar_Click(object sender, ImageClickEventArgs e)
{
int intBytes = 0;
string strArchivos = "";
string strRutaArchivos = "";
bool blnBytes = true;
bool blnPermitir = true;
try
{
HttpFileCollection hfc = Request.Files;
//Check if all files together are less than 10mb
foreach (HttpPostedFile hpf in hfc)
{
intBytes += hpf.ContentLength;
if (intBytes > 11000000)
{
blnBytes = false;
break;
}
}
if (blnBytes)
{
//Upload All attached files to server
foreach (HttpPostedFile hpf in hfc)
{
if (hpf.FileName == "")
{
break;
}
string strNombre = ((int)Session["Grupo"]) + "_" + (int)Session["EmailIdCliente"] + "_" + DateTime.Now.ToString("MM-dd-yyyy_HH.mm.ss") + "_" + Path.GetFileName(hpf.FileName);
strArchivos += strNombre + ";";
strRutaArchivos += Server.MapPath("~/Archivos/") + strNombre + ";";
hpf.SaveAs(Server.MapPath("~/Archivos/") + strNombre);
}
}
}
catch
{
blnPermitir = false;
}
if (!blnBytes || !blnPermitir)
{
//Error Message Displayed To User
ClientScript.RegisterStartupScript(this.GetType(), "Mensaje", "alert('Maximo Puede Enviar 10MB En Archivos');", true);
}
else
{
//Moving on to send email
}
}
What I want is that if blnBytes equals false (it becomes false when all combined files are more than 10mb) it just displays an error message, but how can I make it work even if a single file is larger than 10mb??....
Hope you can help me with that thanks