1

Currently, I enter the exact file location like "c:\mydir\myfile.txt" in the input text box and hit the submit button. This gets captured as a string and posted to my webapi controller.

    <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;
            });
    }
}]);

I want to

1) click the button

2) choose file name from the windows explorer

3) choose the above mentioned file.

4) take the PATH of the file and submit to the web api controller

How can I do that in angularjs?

dotnet-practitioner
  • 13,158
  • 35
  • 123
  • 195

1 Answers1

0

Try changing the first <input> from "type=text" to "type=file" then once you have selected the file, the <input> value will be the path to the file.

Simple string manipulation should get you what you want. Then the rest is easy.... ;o)

EDIT

It is not possible to get the PATH, just the filename: How to resolve the C:\fakepath?

Community
  • 1
  • 1
Jonathan Smith
  • 2,112
  • 27
  • 51