Tutorials to .com

Tutorials to .com » Asp » Fso » Using XML + FSO + JS to achieve server-side file

Using XML + FSO + JS to achieve server-side file

Print View , by: iSee ,Total views: 12 ,Word Count: 2317 ,Date: Thu, 16 Apr 2009 Time: 4:50 AM

First of all, the server side to create a procedure to generate xml documents in order to return to the client, (getfolder.asp)
<%
'written by Linzhang Chen ,2003-4-20
'Reprint please specify the source and retain the copyright information
response.write "<? xml version =" "1.0" "encoding =" "GB2312 ""?>"& chr (13)
response.write "<mediafile>" & chr (13)
folders = request ( "folder")
if folders = "/" then
folders = ""
end if
dim count
count = 0
folders = replace (folders ,"..","")
basefolder ="../ media / " 'benchmark folder path
newfolder = basefolder & folders
Set fso = server.CreateObject ( "Scripting.FileSystemObject")
set f = fso.getfolder (server.mappath (newfolder))
set sf = f.subfolders
for each fd in sf 'to return to the specified folder path to the following list
response.write "<file>" & chr (13)
response.write "<ftype> folder </ ftype>" & chr (13)
response.write "<fname>" & fd.name & "</ fname>" & chr (13)
response.write "</ file>" & chr (13)
count = count +1
next
set sf = nothing
set ff = f.Files
for each fi in ff
fname = fi.name
if instr ( "asf, wma, wmv", lcase (mid (fname, instrrev (fname ,".")+ 1)))> 0 then 'set the file types allowed to return to prevent the source code leak
response.write "<file>" & chr (13)
response.write "<ftype> file </ ftype>" & chr (13)
response.write "<fname>" & fname & "</ fname>" & chr (13)
response.write "</ file>" & chr (13)
count = count +1
end if
next
'If the directory does not document, made an empty element
if count = 0 then
response.write "<file>" & chr (13)
response.write "<ftype> empty </ ftype>" & chr (13)
response.write "<fname> 0 </ fname>" & chr (13)
response.write "</ file>" & chr (13)
end if
response.write "</ mediafile>"
set ff = nothing
set f = nothing
set fso = nothing
%>
The following is the JS client had done (selectfile.asp)
<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN">
<HTML>
<HEAD>
<TITLE> Select the video file </ TITLE>
<style>
td (font-size: 9pt)
select (width: 210)
. s2 (width: 250)
</ style>
<SCRIPT LANGUAGE="javascript">
<! --
/ * written by Linzhang Chen ,2003-4-20
Reprint please specify the source and retain the copyright information * /

/ / Pre-loaded picture
var imgback = new Image ();
imgback.src = "images / arrow.gif";
var imgbackgray = new Image ();
imgbackgray.src = "images / grayarrow.gif";
var imgfolder = new Image ();
imgfolder.src = "images / folder.gif";
var imggrayfolder = new Image ();
imggrayfolder.src = "images / grayfolder.gif";
/ / Stack array history
var arrhistory = new Array ();
var hisi = 0;
/ / Used to determine the file name to return
function check ()
(
if (document.all.filename.value =="")
(
alert ( "Please select the file");
return false;
)
else
(
window.returnValue = document.f1.folder.value + document.all.filename.value;
window.close ();
)
)
/ / Get the contents of xml documents
function getuserlist (url)
(Var oXMLDoc = new ActiveXObject ( 'MSXML');
oXMLDoc.url = url;
var ooRoot = oXMLDoc.root;
return ooRoot;
)
/ / Election of a document, this value back to the text box
function addfile (txt)
(
document.all.filename.value = txt;
)

var first = 1; / / Define a global variable

function userlist (folders, ti) / / list box by
(document.f1.folder.value = folders;
filebox.document.body.innerHTML = "file is loaded, please wait ...";
var strshow = "";
var timeoutid = null;
var newfolder = "";
var arrfolder = new Array ();
var arrff = new Array ();
var blankstr = "";
var oItem;
/ / Determine the history of the state of
hisi + = ti;
arrhistory [hisi] = folders;
if (hisi == 0)
(
arrow.innerHTML = "<img src=\"images/grayarrow.gif\">";
)
else
(
arrow.innerHTML = "<img src = \" images / arrow.gif \ "border = 0 style = \" cursor: hand \ "onclick = \" userlist ( ' "+ arrhistory [hisi-1 ]+"',- 1) \ "onmouseover = \" this.src = 'images / arrow_over.gif' \ "onmouseout = \" this.src = 'images / arrow.gif' \ ">";
)
/ / Determine the current folder
if (document.f1.folder.value =="")
(
folderid.innerHTML = "<img src=\"images/grayfolder.gif\">"
)
else
(newsfolder = checkfolder (document.f1.folder.value)
folderid.innerHTML = "<img src = \" images / folder.gif \ "border = 0 style = \" cursor: hand \ "onclick = \" userlist ( ' "+ newsfolder +"', 1) \ "onmouseover = \ "this.src = 'images / folder_over.gif' \" onmouseout = \ "this.src = 'images / folder.gif' \"> "
)
/ / Assignment to the drop-down box
document.all.select.options.length = 0;
newfolder = folders;
folderstr = ""
var _obj = document.all.select;
var _o = document.createElement ( "Option");
_o.text = "Select Folder";
_o.value = "";
_obj.add (_o);
if (newfolder !="")
(arrfolder = newfolder.split ("/")
for (var i = 0; i <arrfolder.length-1; i + +)
(blankstr + = "";
folderstr + = arrfolder [i ]+"/";
_o = document.createElement ( "Option");
_o.text = blankstr + arrfolder [i]; [AutoPage]
_o.value = folderstr;
_obj.add (_o);

)
)
document.all.select.options [document.all.select.options.length-1]. selected = true;
url = "getfolder.asp.gl? folder =" + folders;
oRoot = getuserlist (url)
strshow = "<table class=file cellspacing=0 cellpadding=0>";
len = oRoot.children.length;
if (len == 1)
(oItem = oRoot.children.item (0);
if (oItem.children.item (0). text == "empty")
strshow = "no files and folders of the";
else
(
if (oItem.children.item (0). text == "folder")
(
strshow + = "<tr> <td> <A href=\"javascript:parent.userlist('"+folders+oItem.children.item(1).text+"/"+"',1)\"> <img src = \ "images / mediafolder.gif \" border = 0> "+ oItem.children.item (1). text +" </ A> </ td> </ tr> ";
)
else
(
strshow + = "<tr> <td> <a href=\"javascript:parent.addfile('"+oItem.children.item(1).text+"')\"> <img src = \" images / mediafile. gif \ "border = 0>" + oItem.children.item (1). text + "</ A> </ td> </ tr>";

)
)
strshow +="</ table> "
)
else (
/ / Data
for (i = 0; i <len; i + +)
(OItem = oRoot.children.item (i);
if (oItem.children.item (0). text == "folder")
(
arrff [i] = "<A href=\"javascript:parent.userlist('"+folders+oItem.children.item(1).text+"/"+"',1)\"> <img src = \ "images / mediafolder.gif \" border = 0> "+ oItem.children.item (1). text +" </ A> ";
)
else
(
arrff [i] = "<A href=\"javascript:parent.addfile('"+oItem.children.item(1).text+"')\"> <img src = \" images / mediafile.gif \ " border = 0 height = 12> "+ oItem.children.item (1). text +" </ A> ";

)
)
/ / Get the number of rows to output
if (len <= 6)
(x = 1;
y = 6;)
else
(x = len / 6;
y = 6;)
for (var i = 0; i <y; i + +)
(strshow + = "<tr>"
for (var j = 0; j <x; j + +)
(ponits = j * y + i;
if (ponits> = len)
(
strshow + = "<td> </ td>";
)
else
(
strshow + = "<td>" + arrff [ponits ]+"</ td> ";
)
)
strshow +="</ tr> "
)

strshow +="</ table> "
)
filebox.document.body.innerHTML = strshow;
)
//-->
</ SCRIPT>
<script LANGUAGE="vbscript">
function checkfolder (folderstr)
if (folderstr = "" or instr (folderstr ,"/")= instrrev (folderstr ,"/")) then
checkfolder = ""
else
nfolder = left (folderstr, len (folderstr) -1)
checkfolder = left (nfolder, instrrev (nfolder ,"/"))
end if
end function
</ script>
</ HEAD>

<BODY Style="margin:0" bgColor=menu onload="javascript:userlist('',0)">
<table width="443" border="0" cellspacing="0">
<tr>
<td height="36"> <table width="409" border="0">
<tr>
<td width="73" align="right"> Look (<u> I </ u >):</ td>
<td width="214"> <select name="select" id="select" size="1" onchange="javascript:userlist(this.value,1);">
</ select> </ td>
<td width="22" valign="baseline" id="arrow" align=right> </ td>
<td width="20" valign="middle" id="folderid"> </ td>
<td width="20" align="left"> <img src="images/md.gif" width="16" height="15"> </ td>
<td width="28" align="left"> <img src="images/viewtype.gif" width="23" height="14"> </ td>
</ tr>
</ table> </ td>
</ tr>
<tr>
<td height="120"> <table width="100%" height="100%" border="0">
<tr>
<td width="9"> </ td>
<td>
<iframe src="blank.htm" width=415 height=120 id="filebox"> </ iframe> </ td>
<td width="13"> </ td>
</ tr>
</ table> </ td>
</ tr>
<tr>
<td height="60"> <table width="100%" border="0">
<FORM METHOD=POST ACTION="" name="f1">
<input type="hidden" name="folder" value="">
<tr>
<td width="85" align="right"> file name (<u> N </ u>): </ td>
<td width="254"> <input type="text" id="filename" size="34"> </ td> [AutoPage]
<td> <button onclick="javascript:return check()"> open (<u> O </ U>) </ button> </ td>
</ tr>
</ FORM>
<tr>
<td align="right"> file type (<u> T </ u >):</ td>
<td> <select name="select2" class=s2>
<option> streaming media file (*. asf, *. wmv, *. wma) </ option>
</ select> </ td>
<td> <input type="button" name="Submit" value="" onclick="window.close();"> </ td>
</ tr>
</ table> </ td>
</ tr>
</ table>
</ BODY>
</ HTML>

There is also a small file used to define blank.htm file and folder display style
<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN">
<HTML>
<HEAD>
<TITLE> New Document </ TITLE>
<style>
td (font-size: 9pt)
body (font-size: 9pt)
. file A (COLOR: # 000000; TEXT-DECORATION: none; font-size: 9pt)
. file A: visited (COLOR: # 000000; TEXT-DECORATION: none; font-size: 9pt)
. file A: hover (COLOR: # 000000; TEXT-DECORATION: none; font-size: 9pt)
</ style>
</ HEAD>

<BODY Style="margin: 0pt">

</ BODY>
</ HTML>
When calling the following function, can be confused as real ones on the server-side document the effects of choice
function selectfile ()
(
var arr = showModalDialog ( "selectfile.asp? temp =" + Math.random (), "", "dialogWidth: 453px; dialogHeight: 252px; status: 0; help: 1");
if (arr! = null)
(
return arr
)
)


ASP File System Object Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.