Blog : Reading the file on client system using Jquery RSS
Reading the file on client system using Jquery RSS
Hi All,
Given a file path on client machine, is it possible for me to get the content of the file from that
location and show that content in browser using any client scripting language.
when i explored on this , i got following information.
1.Client scripting languuages are not allowed to have access to client system as it is a huge
security threat.
2. We can use ActiveXObject (FileSystemObject) to have access to client system, but it has
limitations like it only works in IE & client also need to change IE settings to make sure that this
active x componet runs in his browser.
Does any one have any alternative solutions with Jquery/Ajax or any client scripting language(that is cross browser compatible and works for all file types.)
This information is correct.
The only opportunity you have is to use a file:/// url but that will only send the user to that file. Depending on their set up this may trigger the file as a download or display it in the browser. In either case you wouldn't have any access to the file using jquery or any code thats running in the browser.
The only way around this is to allow the user to upload a file to your server and then manipulate it there.
.
Thank you for your reply. I tried to using file:/// url thing by using following code.but that piece of code is working fine( i mean i am able to see the file content when i clicked on link) when it is placed in stand alone HTML file, but when i placed that code either in aspx or in html page which is a part of an asp.net application that piece of code is not working(i mean when i clicked on link i am unable to see file content) Not sure what is the exact problem.
<head> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function EnableButton() { document.getElementById('AddToList').disabled = ''; } function AddLink(btn) { var div = document.getElementById('Links'); var anchorTag = document.createElement('a'); anchorTag.appendChild(document.createTextNode(document.getElementById('File1').value)); anchorTag.setAttribute('target','_blank'); var path = document.getElementById('File1').value.replace(/\\/g, "/"); alert(document.getElementById('File1').value); alert(path); anchorTag.setAttribute('href','file:///'+ path); div.appendChild(anchorTag); alert(anchorTag.getAttribute('href')); div.appendChild(document.createElement('br')); btn.disabled='disabled'; } </script> </head><body><div> <input id="File1" type="file" onchange="EnableButton();" /> <br /><br /><br /> <input id="AddToList" type="button" value="AddToList" disabled="disabled" onclick="AddLink(this);" /> <br /> <br /> </div> <div id="Links"> </div></body>