By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

Can't open a file in WebDav

P: 5
Hi all
I create a small code that show folders in webdav,
the code is

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. function davhole()
  3. {
  4. website="MYURL"
  5. davshare="/MYFOLDER"
  6. davdiv.navigateFrame(website+davshare,"daviframe");
  7. }
  8. </script>
  9. <div id="davdiv" style="behavior:url(#default#httpFolder)">
  10. </div>
  11.  
  12. <table border="0" cellspacing="0" cellpadding="1" width="100%">
  13.     <tr>
  14.         <td align="left" class="colgauche">
  15.             <iframe scrolling="auto" onload="davhole();" src="" name="daviframe" width="100%" height="200px" frameborder="0">
  16. </iframe>
  17.         </td>
  18.     </tr>
  19. </table>
  20.  
It's work fine - I can open a folders. I can create/delete a folder.
But when I want to work with files - I have a problem.
I can't create a new text file.
I can't open any file. I get a messege like "The filename, directory name, or volume label syntax is incorrect."

How I will work's with files????

Thanks
Roi Kolbinger
Aug 11 '08 #1
Share this Question
Share on Google+
8 Replies


rnd me
Expert 100+
P: 427
i would dump the ie behavior for a real, cross browser dav response parser.

there are libpraries to add/remove files, copy, etc.

you can get the folder info using ajax to fetch a dav response, like a "search" or "propfind", and parse the folder info from the responseXML.
Aug 11 '08 #2

P: 5
How I do it in ajax?

Thanks,
Roi Kolbinger



i would dump the ie behavior for a real, cross browser dav response parser.

there are libpraries to add/remove files, copy, etc.

you can get the folder info using ajax to fetch a dav response, like a "search" or "propfind", and parse the folder info from the responseXML.
Aug 12 '08 #3

acoder
Expert Mod 15k+
P: 16,027
First of all, do you know the basics of Ajax? If not, check out a simple tutorial (see some of the links in the Offsite Links thread).

Then it's just a case of returning the XML from the server to be parsed by JavaScript.
Aug 13 '08 #4

rnd me
Expert 100+
P: 427
there are two distinct ways of calling a dav folder listing. some setup will support the following version, based on propfind. other will need a search request.

let me know if the following does't work, and i will try to find the search-based routine.



Expand|Select|Wrap|Line Numbers
  1. //supporting functions:
  2.  
  3. var IE = (!! document.all);
  4. function now(){ return new Date;}
  5.  
  6.  
  7. if (!Array.prototype.map) {// from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:map
  8. Array.prototype.map = function (fun) {var len = this.length;if (typeof fun != "function") {throw new TypeError;}var res = new Array(len);var thisp = arguments[1];for (var i = 0; i < len; i++) {if (i in this) {res[i] = fun.call(thisp, this[i], i, this);}}return res;};}
  9.  
  10. function obVals(ob) {var r = [];var i = 0;for (var z in ob) {if (ob && ob.hasOwnProperty && ob.hasOwnProperty(z)) {r[i++] = ob[z];}}return r;};
  11.  
  12.  
  13.     function obValsl(ob) {
  14.             if (ob && ob.length) {
  15.                 var r = [], i = 0, mx = ob.length;
  16.                 for (var z = 0; z < mx; z++) {
  17.                     r[z] = ob[z] || undefined;
  18.                 }
  19.             } else { return ["error in obvlasl"]; }
  20.         return r;
  21.     }
  22.  
  23.  
  24. function newajax() {
  25.     var ox = null;
  26.     if (window.XMLHttpRequest) {
  27.         ox = new XMLHttpRequest;
  28.     } else if (window.ActiveXObject) {
  29.         ox = new ActiveXObject("Microsoft.XMLHTTP");
  30.     }
  31.     return ox;
  32. }
  33.  
  34.  
  35.  
  36.  
  37. //dav dir code:
  38.  
  39.  
  40. function getDirDav(p){
  41.     var sets={};
  42.     var TEXT="textContent";
  43.     if(IE){ TEXT="text"; }
  44.  
  45.     function harvestDOM(ina){ //DOM version
  46.         function rake(k,d){ return String((obValsl( ina.getElementsByTagName(k))[0][TEXT]) || d || "untitled" );}
  47.  
  48.         var tname=rake("a:displayname")
  49.         var tpath=rake("a:href", "nopath" );
  50.         var tsize=rake("a:getcontentlength", 0);
  51.         var tdate=rake("a:getlastmodified", now() );
  52.          var qaa={ name:  tname,
  53.                 path: tpath,
  54.                 size: tsize,
  55.                 date: tdate     }
  56.       return qaa;
  57.     }//end harvest DOM
  58.  
  59.     harvest=harvestDOM;
  60.  
  61.   var d33=' <?xml version="1.0" encoding="utf-8" ?>\
  62.    <D:propfind xmlns:D="DAV:">\
  63.      <D:prop xmlns:R="http://www.foo.bar/boxschema/">\
  64.     <D:displayname/>\
  65.     <D:getcontentlength/>\
  66.     <D:getlastmodified />\
  67.      </D:prop>\
  68.    </D:propfind>'
  69.  
  70.        function mr(d) {
  71.             var XHRt = newajax();
  72.             XHRt.open("PROPFIND", d, false);
  73.             XHRt.setRequestHeader('Content-Type', 'text/xml')
  74.             XHRt.setRequestHeader('Depth', '1')
  75.             XHRt.send(d33.toString());
  76.             return XHRt.responseXML;
  77.         }
  78.  
  79.     var  g =mr(p);
  80.  
  81. //     rs = obValsl(g.documentElement.getElementsByTagName("response"));
  82.         rs =obValsl(g.documentElement.getElementsByTagName("a:response"));
  83.     rr= obVals(rs).map(function(a){ if(a) return harvest(a) });
  84.     return rr
  85. } //end getdavdir
  86.  
  87. //usage: 
  88. getDirDav(  url Path )
  89.  
  90.  
no guarantees on any of this.
i kinda pasted and quickly edited everything together.
i will be very busy these next few days, but if you are still stuck this weekend, we can try to sort everything out. i had to change the namespace to a, not sure if that matters. i tested it on firefox on iis, might need some coaxing to be xbrowser.

keep me posted.

good luck!
Aug 13 '08 #5

P: 5
Thanks a lot...

I know a little of AJAX, and as I know, I need to write Server code (like C#) that work with AJAX. The code here is build in on WebDav server?

Where I need to write my url? I wrote someting like that, and it didn't work:

getDirDav(myUrlWebDavServer);

Did I miss something?

Thanks again
Roi
Aug 14 '08 #6

rnd me
Expert 100+
P: 427
try
getDirDav(".");

and let me know if you see anything at all.

it should be an array of objects, that you can easily turn into an html table or whatever in a loop.

you should try using firebug to peek at the effects of running the code. you can look at the responses to various tweaks, and explore the arrays that come back from the directory listing function.
Aug 14 '08 #7

P: 5
Thanks I will try...
Aug 20 '08 #8

P: 5
Hi, I soroy that It take me time to answer you

when I use :
Expand|Select|Wrap|Line Numbers
  1. getDirDav(".");
I get "error in obvlasl"
on
Expand|Select|Wrap|Line Numbers
  1. rs =obValsl(g.documentElement.getElementsByTagName("a:response"));
Thanks,
Roi
Aug 24 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.