var checkFileIsExist = function (fileName) {
var url = "/_api/Web/lists/getByTitle('" + SharePointList.stpDoc + "')/Items?$select=FieldValuesAsText/FileRef&$expand=FieldValuesAsText&$filter=FileLeafRef
eq '" + fileName + "'";
return baseService.getRequest(url);
};
baseService.js
var getRequest = function (query) {
var deferred = $q.defer();
$http({
url:
_spPageContextInfo.webAbsoluteUrl + query,
method: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-Type": "application/json;odata=verbose"
}
}).then(function (result) {
deferred.resolve(result);
}, function (result, status) {
deferred.reject(status);
});
return deferred.promise;
};
Controller :
stppService.checkFileIsExist("" + file.name + "").then(function (response) {
if (response.data.d.results.length
> 0) {
alert("This file already exists, Please Rename file and upload
again !!!");
}
No comments:
Post a Comment