1

I am writing a small web service for a private project using C# and ASP.net. Part of this is uploading a text file via an HTML form:

<input type="file" name="File" id="File" />

for server side analysation. This works but now i need to analyse the local path also. So the server needs to get the local path as a string. But currently i have no real idea how to achieve that. One idea i have is to use javascript to catch the local path and add it to the form in a additional text field. But i am not very proficient in javascript so I do not know how to do it.

edit: On the server the file is directly converted (IFormFile -> MemoryStream) i never touch the filename in any way. But anyway i expected that security reasons are preventing what I initially wanted.

So when, in the end, the user has to give the path by itself, would it be possible to use this information directly for uploading the file? So that i can remove the type="file" input and have the user only perform action not two? But i guess that would be problematic also, because the browser would then need to have access to the file system right?

Oliver
  • 149
  • 1
  • 9
  • [HttpPostedFile.FileName](https://learn.microsoft.com/en-us/dotnet/api/system.web.httppostedfile.filename?view=netframework-4.7.2) what code do you use on the server to handle the filename? – Steve Apr 11 '19 at 13:32
  • @Steve In most browsers that will not include the path - just the filename. – mjwills Apr 11 '19 at 13:35
  • 1
    document.getElementById('File').value will return either the name of the file or a fakepath, depending on the browser. You will never know the full path to the file on the client machine without asking the user to provide the full path to you in a form field. – daddygames Apr 11 '19 at 13:43

0 Answers0