Hello i am trying to send xml file to the web-method using HttpPost but in the wbmethod i am getting exception in ,
var file = HttpContext.Current.Request.Files[0]
because Files count is zero , can any one help ?
$scope.SelectFileForUpload = function (file) {
if (file != undefined && file != null && file.length != 0) {
if (file.length < 2) {
if (file[0].type == 'text/xml') {
$scope.TransitionOfCareImport.File = file[0];
$scope.GenerateHtml($scope.TransitionOfCareImport.File);
}
else {
alert("Xml Allowed Only");
angular.forEach(angular.element("input[type='file']"),function (inputElem) {
angular.element(inputElem).val(null);
});
}
}
else {
alert("Multiple files are not allowed");
}
}
var formDaata = new FormData();
formDaata.append("file", file);
http({
url: myUrl,
method: method,
contentType: "application/json",
data: formDaata ,
dataType: "json",
})
.success(function (data, status, headers, config) {
alert("success");
})
.error(function (data, status, headers, config) {
alert(data.Message);
});
}
and in my webmethod:
WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public static string GenerateHtmlFromXml()
{
if (HttpContext.Current.Request.Files != null)
{
var file = HttpContext.Current.Request.Files[0];
}
return string.Empty;
}