Thursday, November 12, 2009

Read files through Javascript

I Came across a scenario, i.e, as follows

1) An ASP.Net application is configured in a server.
2) I need to open a file from client side in a text area(the file can be any type)
3) I can modify it
4) I need to save the modifications in the same path of client

Here we can’t open the file in Fileupload control, since it uploads the file to the server location. The modified file can’t be save in the clients location.
So, I went for Javascript. I just copy a code for illustration

<form id="form1" runat="server">
<input type=text id="txtFile" /><input type="button" id="btnSub" value="Open" onclick="ReadFiles();" />
 <textarea id="txtFileData" name="S1"></textarea></div>

function ReadFiles()
var txt=document.getElementById('txtFile').value;
var fso, f1, ts, s;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso.OpenTextFile(txt, ForReading);
s = ts.ReadLine();
s=s + ts.ReadLine();



But here the Browser settings should enable the activeX objects.

No comments:

Post a Comment


Obstacles are those frightful things you see when you take your eyes off your goal.------> by Henry Ford