0

Is it possible to use something like input type=file where I can choose a file on my computer and then get the filepath? I use HTML5, JQ/JS

EDIT: If it's possible with C# I can use that as well.

I just want a HTML-button that is clicked on and then the user can browse file, and that filepath is what I want

A. Wolff
  • 74,033
  • 9
  • 94
  • 155
MrProgram
  • 5,044
  • 13
  • 58
  • 98

2 Answers2

0

html5 support a file API

if (window.File && window.FileList) {
    $(element)[0].files;
}
MaiKaY
  • 4,422
  • 20
  • 28
0

The easiest way to achieve it is through this

<input type="file" name="uploadFile">

Then you can use javascript (as mentioned in comment section bellow your original question) to get path. But you won't get full path, modern browsers don't allow that.

You also asked for C# solution, this could work for you:

using System;
using System.IO;
class Program
{
    static void Main()
    {
        string path = "C:\\stagelist.txt";
        string extension = Path.GetExtension(path);
        string filename = Path.GetFileName(path);
        string filenameNoExtension = Path.GetFileNameWithoutExtension(path);
        string root = Path.GetPathRoot(path);
    }
}
FanaticD
  • 1,416
  • 4
  • 20
  • 36