打开文件对话框并识别文件的确切位置

时间:2015-04-28 17:15:07

标签: angularjs

目前,我输入的确切文件位置如" c:\ mydir \ myfile.txt"在输入文本框中,然后单击“提交”按钮。这会被捕获为一个字符串并发布到我的webapi控制器。

    <div data-ng-controller="fileCtrl">
        <form novalidate class="simple-form">
            <input type="text" placeholder="Enter full file path here.." data-ng-model="filePath" />
            <input type="submit" data-ng-click="LoadFilePath()" value="Submit" />

            <div ui-grid="{ data: Rates }" class="grid"></div>

            <p>Copy / Paste : </p>
            <textarea style="height:200px; width:1000px; overflow:scroll;">{{InsertSQL}}</textarea>

        </form>
    </div>

app.controller('fileCtrl', ['$scope', '$http', function ($scope, $http) {

    $scope.LoadFilePath = function () {
        //console.log('file path is ' + $scope.filePath);
        $http
            .post('http://localhost:1229/api/Rates' + '/processfile', '"' + $scope.filePath + '"')
            .success(function (data) {
                $scope.Rates = data.Rates;
                $scope.InsertSQL = data.InsertSQL;
            });
    }
}]);

我想

1)点击按钮

2)从Windows资源管理器中选择文件名

3)选择上面提到的文件。

4)获取文件的PATH并提交给web api控制器

我怎么能在angularjs中做到这一点?

1 个答案:

答案 0 :(得分:0)

尝试将第一个<input>从“type = text”更改为“type = file”,然后在选择文件后,<input>值将成为文件的路径。

简单的字符串操作应该可以满足您的需求。然后其余的很容易......; o)

编辑

无法获取PATH,只能获取文件名:How to resolve the C:\fakepath?