AlexGH AlexGH - 1 year ago 106
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(

@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" />

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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download