HttpPostedFileBase - Bringing null when I have many files with the big name

1

Good morning Friends next

I have a mvc web system with C # and need to upload multiple files simultaneously. Until then, okay, but when the files have a big name of the problem I'll exemplify.

I have 5000 xmls to import with the name "NFe35160870940994008196550100004554491586403310.xml"

When I select 10 to 20 files all go to the controler, now above that goes null.

Now when I change the file name to "A" by getting A (1), A (2) ... send it to the controler up to 2000 at a time.

I do not know what to do, increase maxRequestLength to the maximum

Follow the code that I use CSHTML

 @using (Html.BeginForm("ImportarXML", "LeituraNfe", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="col-md-12">
        <div class="col-md-4">
            <label>Selecione arquivos para importação</label><br />
            <input type="file" multiple="multiple" name="postedFilesBases" />
        </div>
        <div class="col-md-2">
            <label></label><br />
            <input type="submit" value="Importar" class="btn btn-primary btn-sm" />
        </div>
    </div>
}

Controller

public ActionResult ImportarXML(List<HttpPostedFileBase> postedFilesBases)
{
    try
    {
        var h = new List<XmlDocument>();
        foreach (var item in postedFilesBases)
        {
            var document = new XmlDocument();
            document.Load(item.InputStream);
            h.Add(document);
        }
		postedFilesBases.Clear();
		foreach (var item in h)
		{
			//Faça algo
		}
	}
	cath(Exception ex)
	{
		//erro
	}
}
    
asked by anonymous 28.06.2018 / 17:25

1 answer

0

Hello, I solved the problem just by changing to upload the complete directory instead of the individual files. See below how the code snippet was noticed on the commented line that was before and now like this

@using (Html.BeginForm("ImportarXML", "LeituraNfe", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="col-md-12">
        <div class="col-md-4">
            <label>Selecione arquivos para importação</label><br />
            <input type="file" name="postedFilesBases" directory mozdirectory webkitdirectory/>
            @*<input type="file" multiple="multiple" name="postedFilesBases" />*@
        </div>
        <div class="col-md-2">
            <label></label><br />
            <input type="submit" value="Importar" class="btn btn-primary btn-sm" />
        </div>
    </div>
}
    
18.07.2018 / 13:15