Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File list using xmlhttp?

Status
Not open for further replies.

benniesanders

Programmer
Jan 20, 2002
199
US
Greetings, I normally work on windows servers but I have a non windows site that I am re-doing. I would like to get a list of images from the image file without having to drag each image to a page. Is there a way to do this through xmlhttp or some other form of xml? The reason I wanted to use xmlhttp is because I can use my asp development site to provide a list of images and a checkbox next to each one so the site owner can check off the images he wants to keep. Any thoughts would be greatly appreciated. Thanks!
 
This is how you can get the list of file name in the ./pictures directory on the server relative to the working directory of the html page. I construct a dedicated asp file to do it.
[1] In general, you can construct an asp to receive the request and call for different processes to be call (rpc). But, here the dedicated asp page performs only one function.
[2] The response is of text/xml. You can as well just comma delimited text string with no relation with xml technology.
[3] The xml is bare skeleton and you can beef it up to look intimating to uninitiated.
[4] The html is for ie only. It can easily to extend to cross-browser (moz/ff) by standard ritual.

I draft this up in express and no pretention of sophistication. Just bare minimal with all essential elements shown.

[a] The html page.
[tt]
<html>
<head>
<script language="javascript">
function doit() {
var oxmlhttp=new ActiveXObject("msxml2.xmlhttp");
with (oxmlhttp) {
async=false;
open ("get","[green]response.asp[/green]");
send (null);
}
var oparser=oxmlhttp.responseXML;
var s=oparser.xml;
s=s.replace(/\</g,"&lt;");
s=s.replace(/\>/g,"&gt;");
document.getElementById("divid").innerHTML="<pre>" + s +"</pre>";
oxmlhttp=null;
}
</script>
</head>
<body>
<button onclick="doit()">send xmlhttp requesting remote procedure</button><br />
<div id="divid" style="word-wrap:break-word;"></div>
</body>
</html>
[/tt]
The response.asp (rpc functional)
[tt]
<%
response.contenttype="text/xml"
set oparser=server.createobject("msxml2.domdocument")
set oprolog=oparser.createProcessingInstruction("xml","version='1.0' encoding='utf-8'")
oparser.appendchild oprolog

set oroot=oparser.createelement("root")

spath=server.mappath("pictures")
set fso=createobject("scripting.filesystemobject")
set ofolder=fso.getfolder(spath)
for each ofile in ofolder.files
set oelem=oparser.createelement("file")
set otext=oparser.createtextnode(file.name)
oelem.appendchild otext
oroot.appendchild oelem
next
oparser.appendchild oroot
response.write oparser.xml
set ofolder=nothing
set fso=nothing
set oroot=nothing
set oprolog=nothing
set oparser=nothing
%>
[/tt]
Rather than displaying in a div, the response is in a parsed xml document ready for dom operation. What to do with it is only limited to your imagination.
 
Hi tsuji,

Many, many thanks for your input but I'm not smart enough to know how to use it. Where do these files go? I tried putting the html on my server and the response.asp on the other server, but as I mentioned, the other server is not a windows server. ASP is not enabled. Any other thoughts? What exactly am I doing wrong or probably a better question is what am I supposed to be doing?

Thanks again
 
The response.asp is reachable from the server. If the server is not supporting asp, (running unix or not), it should be whatever server-side language it be, php or perl or jsp. (You mention you master asp, that's why I put up an asp that I feel comfortable enough as well.) After replacing that, it functions exactly the same only changing the url to whatever such as response.php or .pl or jsp etc...

The html page is from the client browser. There is nothing holding it back to be another asp page on the other server on windows os. In that case, make no intereactive (button click) like I show but replace the trigger by other means. You initiate server-side msxml2 (free-threaded if the preliminary functionality is tested thoroughly---but leave it alone for the moment.) And then it becomes a server-to-server xmlhttp request which is equally supported.

But, I certainly cannot involved myself into all these as there is a big technology recept behind it, plus, quite a bit of technical detail of settings badly ready for discussing through like this.
 
Amendment
The original line
open ("get","response.asp");
should be read like this.
[tt]open ("get","response.asp"[red],false[/red]);[/tt]
(Though functionally the same, but is more neat.)
 
Thanks again, Tsuji, I should have said I was doing this from a remote server. I'll give this a try and let you know how it works out. many thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top