Hi
I have to create an HTML page for a Windows Azure application where the user can select a file (.CSV particularly) from the file uploader and read its contents, analyze the contents and then upload the analyzed information to the Azure application. I have
to do all this in JavaScript only. No server code involved.
Second thing is that the users of the application shall only be allowed to use only IE7+, no other browser.
Here is my code...
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Reading File</title>
<script>
function ReadFile() {
var file = document.getElementById('file');
// Read file in Internet Explorer
if (checkBrowser("MSIE")) {
var forReading = 1, forWriting = 2, forAppending = 8;
if (file.value != "") {
name = file.value.replace("\\", "\\\\");
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(name)) {
f = fso.GetFile(name)
if (f.size) {
if (f.Type == "CSV File") {
f = fso.OpenTextFile(name, forReading);
if (f) {
var txt = f.ReadAll();
alert(txt);
f.close
}
else
alert("Error while opening the file");
}
else
alert("Only CSV files are supported");
}
else
alert("File is empty");
}
else
alert("File Not Found");
}
else
alert("No file selected to read");
}
}
function checkBrowser(browserName) { return navigator.userAgent.indexOf(browserName); }
</script>
</head>
<body>
<input type="file" id="file" />
<br />
<input type="button" onclick="ReadFile();" value="Read File" />
</body>
</html>
The problem with the code runs perfectly outside the web-server (as a simple web-page, though we have to allow ActiveX in the IE browser every time a request is made to read the file), but inside and
Web application and Azure application, it just does not work.
In Web Application, on the line var fso = new ActiveXObject("Scripting.FileSystemObject");
I get the error message
Microsoft JScript runtime error: Automation server can't create object
In the Azure Application, on the line for (i = 0; i < files.length; i++), I get the error message
Microsoft JScript runtime error: 'length' is null or not an object
I know it's all about ActiveX in IE.
Is there ever a way to run this code in .HTML page in
IE7+ in Azure?
Any help please?
Kumar Kush (Impetus Infotech (India) Pvt. Ltd.)