I have a web app that when a button is clicked it will read a text file on the users c drive and display the results of the text file.
StreamReader re = File.OpenText(@"c:\Datadetails\serverresults.bcp");
string input = null;
while ((input = re.ReadLine()) != null){
Label1.Text = (input);
}
I have used the above code and when the button is clicked it displays data from the servers c drive only. I need client side code that can read a file on the users local c drive and display it to the user,
The code below is a javascript function that is suppose to get the data client side but I cannot get this to work when a button is clicked. Does anyone know how I could place this in a button control to get this working.
Thanks for any help if anyone knows how to resolve this
function ReadFromFile() {
var strContent = ReadFileToString(document.Form1.TxtFileName.value);
document.Form1.HdnContent.value = strContent;
document.Form1.submit();
}
function ReadFileToString(strFileName) {
var strContents;
strContents =
"";objFSO =
new ActiveXObject("Scripting.FileSystemObject"); if (objFSO.FileExists(strFileName)) {strContents = objFSO.OpenTextFile(strFileName, 1).ReadAll();
}
return strContents;
I tried placing this in Page.ClientScript.RegisterStartupScript but could not work out the correct syntax.
Rafiq BatchaPosted Apr 10, 2008, 8:23 PM
You have to make sure the following:
Your browser should have access to run ActiveX objects. If receive a error message like "Automatic Server Can't Create Object" you most go to Internet Option and in security tab select custom level in Local part and change options to get effect.
ActiveX objects will work only in IE, i guess.