项目需要将用户的部分信息到处到客户端的指定位置上,要求具体到磁盘根目录,花了些时间做了一个界面。
GetDiskInfo()函数用于获得盘符信息,并添加到HTML控件SELECT中。
ExportKey()函数用于确定用户选定的位置并将信息写入该位置下的userkey.txt文件中。
<
HTML
>
< HEAD >
< title > 导出 </ title >
< script language = " javascript " >
function GetDiskInfo()
... {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var drives = fso.Drives;
var e = new Enumerator(drives);
var selectInfo = document.getElementById("selectList");
for(; !e.atEnd(); e.moveNext())
...{
var anOption = document.createElement("OPTION");
anOption.text = e.item().Path;
selectInfo.add(anOption);
}
}
function ExportKey()
... {
var key = window.document.Form1.<%= this.UserInfoTextBox.ClientID %>.value;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var e = new Enumerator(fso.Drives);
var path = window.document.Form1.selectList.options[window.document.Form1.selectList.selectedIndex].text + "/userkey.txt";
for(var i = 0; i < (window.document.Form1.selectList.selectedIndex - 1); i++)
...{
e.moveNext();
}
if(e.item().IsReady)
...{
f1 = fso.CreateTextFile(path, true);
f1.Write(key);
f1.Close();
alert("完成导出!");
}
else
...{
alert("你所选的存储位置存在问题,请重新输入!");
}
}
</ script >
</ HEAD >
< body onload = " GetDiskInfo(); " MS_POSITIONING = " GridLayout " >
< form id = " Form1 " method = " post " runat = " server " >
< FONT face = " 宋体 " >
< SELECT id = " selectList " style = " Z-INDEX: 101; LEFT: 8px; WIDTH: 112px; POSITION: absolute; TOP: 8px " >
< OPTION ></ OPTION >
</ SELECT >
< INPUT onclick = " ExportKey(); " style = " Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 8px " type = " button " value = " 导出 " >
< asp:TextBox id = " UserKeyTextBox " style = " Z-INDEX: 103; LEFT: 136px; POSITION: absolute; TOP: 64px "
runat = " server " Height = " 0px " Width = " 0px " ></ asp:TextBox ></ FONT ></ form >
</ body >
</ HTML >
< HEAD >
< title > 导出 </ title >
< script language = " javascript " >
function GetDiskInfo()
... {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var drives = fso.Drives;
var e = new Enumerator(drives);
var selectInfo = document.getElementById("selectList");
for(; !e.atEnd(); e.moveNext())
...{
var anOption = document.createElement("OPTION");
anOption.text = e.item().Path;
selectInfo.add(anOption);
}
}
function ExportKey()
... {
var key = window.document.Form1.<%= this.UserInfoTextBox.ClientID %>.value;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var e = new Enumerator(fso.Drives);
var path = window.document.Form1.selectList.options[window.document.Form1.selectList.selectedIndex].text + "/userkey.txt";
for(var i = 0; i < (window.document.Form1.selectList.selectedIndex - 1); i++)
...{
e.moveNext();
}
if(e.item().IsReady)
...{
f1 = fso.CreateTextFile(path, true);
f1.Write(key);
f1.Close();
alert("完成导出!");
}
else
...{
alert("你所选的存储位置存在问题,请重新输入!");
}
}
</ script >
</ HEAD >
< body onload = " GetDiskInfo(); " MS_POSITIONING = " GridLayout " >
< form id = " Form1 " method = " post " runat = " server " >
< FONT face = " 宋体 " >
< SELECT id = " selectList " style = " Z-INDEX: 101; LEFT: 8px; WIDTH: 112px; POSITION: absolute; TOP: 8px " >
< OPTION ></ OPTION >
</ SELECT >
< INPUT onclick = " ExportKey(); " style = " Z-INDEX: 102; LEFT: 128px; POSITION: absolute; TOP: 8px " type = " button " value = " 导出 " >
< asp:TextBox id = " UserKeyTextBox " style = " Z-INDEX: 103; LEFT: 136px; POSITION: absolute; TOP: 64px "
runat = " server " Height = " 0px " Width = " 0px " ></ asp:TextBox ></ FONT ></ form >
</ body >
</ HTML >