function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fso1 = new ActiveXObject("Scripting.FileSystemObject");
var filename=document.getElementById('emp_name').value;
var file_path="c:\\vijay\\"+filename+".txt";var image_path="c:\\vijay\\"+filename+"_img.txt";
if(fso.FileExists(file_path) && fso1.FileExists(image_path))
{
alert('Employee Record Found');
}
else
{
var file_details = fso.CreateTextFile(file_path, true);
var image_details = fso1.CreateTextFile(image_path, true);
var fname=document.getElementById('fname').value;
var lname=document.getElementById('lname').value;
var pic=document.getElementById('pic_file').value;
document.getElementById('img').src=pic;
image_details.writeLine(document.getElementById('pic_file').value);
file_details.WriteLine("FIRST NAME :"+fname);
file_details.WriteLine("LAST NAME :"+lname);
file_details.Close();
}}
function readfile()
{
var filename=document.getElementById('emp_show').value;
var strContents,img_cont; strContents = "";
img_cont="";
var strFileName="c:\\vijay\\"+filename+".txt";
var img_filename="c:\\vijay\\"+filename+"_img.txt";
Fileobject = new ActiveXObject("Scripting.FileSystemObject");
Fileobject1=new ActiveXObject("Scripting.FileSystemObject");
if (Fileobject.FileExists(strFileName) && Fileobject1.FileExists(img_filename))
{
strContents = Fileobject.OpenTextFile(strFileName, 1).ReadAll();
document.getElementById('t1').value=strContents;
img_cont=Fileobject1.OpenTextFile(img_filename, 1).ReadAll();
document.getElementById('img2').src=img_cont;
}
else
{
alert('Employee Name Not found');
}}
function del_emp()
{
var filename=document.getElementById('del_emp').value;
var strFileName="c:\\vijay\\"+filename+".txt";
var img_filename="c:\\vijay\\"+filename+"_img.txt";
fileobj=new ActiveXObject("Scripting.FileSystemObject");
fileobj_img=new ActiveXObject("Scripting.FileSystemObject");
file_value=fileobj.GetFile(strFileName);
file_img_value=fileobj.GetFile(img_filename);
file_value.Delete();
file_img_value.Delete();
alert('File Deleted');
}
No comments:
Post a Comment