Home Why can't I access FileName of uploaded file in ASP.NET MVC when uploaded using Microsoft Edge?
Reply: 1

Why can't I access FileName of uploaded file in ASP.NET MVC when uploaded using Microsoft Edge?

Garret Prestwood
1#
Garret Prestwood Published in 2017-12-07 17:37:20Z

I have a simple file upload page and an ASP.NET MVC Controller to process the uploaded file. In Chrome and Firefox, everything works as expected. But it seems that Edge uploads the file differently, such that the Controller sees that a file has been uploaded, but shows FileName as "" and ContentLength as 0.

Here is the cshtml:

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <h3>Upload File</h3>
    File:
    <input type="file" name="UploadedFile" />
    <input type="submit">Submit</button>
}

And in the controller I have:

HttpPostedFileBase file = Request.Files["UploadedFile"];

Afterward the file object is not null, but its ContentLength is 0 and FileName is an empty string. With Chrome and Firefox, these values contain the correct data.

What is different about how Edge handles file uploads?

Garret Prestwood
2#
Garret Prestwood Reply to 2017-12-08 03:47:54Z

The problem was not with my code. I was uploading an Excel spreadsheet that was also open in Excel at the same time, and Edge uploads Word and Excel files as 0 bytes when the file is open.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.327649 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO