AlexGH AlexGH - 1 month ago 6
C# Question

getting a different path when using Chrome or Internet Explorer

this is my code:

public ActionResult PostFile(HttpPostedFileBase file, int NoteId)
{
FileInfo f = new FileInfo(file.FileName);
string fullname = f.FullName; //fullname changes depending on if I am using IE or Chrome
}


This is my View(
PostFile.cshtml
):

@model RiPSShared.Models.RiPSModels.AgencyNote
<form action="@Url.Action("PostFile", "AgencyNotes", new { NoteId=Model.aut_id})" method = "post" enctype="multipart/form-data">
<label for="file1"> File name:</label>
<input type="file" name="file" id="file1" />
<input type="submit" value="Submit" />
</form>


Why am I getting a different path for the file parameter? When I'm using IE is the correct path
("C:\\Users\\User\\Desktop\\sds - Copy (5).docx")
but when using Chrome I get the wrong path:
C:\Program Files (x86)\IIS Express\


I'm using the variable fullname to get the path value...

Answer

IE apparently posts the entire original path, which is a security disclosure issue. Fortunately Chrome doesn't, so you only receive the plain file name, which is then augmented by your calls to new FileInfo(file.FileName).FullName in the running context of your IISExpress process.