2017-04-14 6 views
1

Ich habe dieses Skript geschrieben, Laufwerk nach Dateien im Besitz eines bestimmten Benutzers zu suchen- Es funktioniert gut, außer dieser Funktion, gibt alle Ergebnisse zurück und die Links sind so eingerichtet, dass sie wie ein Dokument geöffnet werden. Also pdf's und andere Dateien Ich bekomme einen Fehler beim Öffnen weil die URL falsch ist. Gibt es generische Möglichkeiten, Dateien zu öffnen, oder muss ich if-Anweisungen schreiben? Irgendwelche möglichen Ideen, wie man das umgehen kann? DankWeb App Link, um alle Dateien in Laufwerk anzuzeigen

function handleResults(results){ 
 
     console.log('Handle Results was called! '); 
 
     document.writeln('<a href="https://script.google.com/a/macros/35634534534534534534534534534">BACK</a><br/><br/>'); 
 
     var length=results.length; // total elements of results 
 
     for(var i=0;i<length;i++) 
 
     { 
 
     var item=results[i]; 
 
     item=item.split("|~|"); // split the line |~|, position 0 has the filename and 1 the file id 
 
      
 
     document.writeln("<b><a href='https://docs.google.com/document/d/"+item[1]+"' target='_blank'>"+item[0]+"</b></a> (Last modified: "+item[2]+")<br/><br/>"); // write result 
 
     
 
     } 
 
     document.writeln("End of results..."); 
 
     }

+2

Haben Sie versucht, 'File.getUrl()'? Die Dokumentation zur API lautet [hier] (https://developers.google.com/apps-script/reference/drive/file). – SpiderPig

Antwort

0

Dank @spiderPig für den Einsatz von File.getUrl();

function handleResults(results){ 
 
     console.log('Handle Results was called! '); 
 
     document.writeln('<a href="https://script.google.com/a/macros/35634534534534534534534534534">BACK</a><br/><br/>'); 
 
     var length=results.length; // total elements of results 
 
     for(var i=0;i<length;i++) 
 
     { 
 
     var item=results[i]; 
 
     item=item.split("|~|"); // split the line |~|, position 0 has the filename and 1 the file URL 
 
     // i changed item1 to contain the file.getUrl instead of the fileId 
 
     document.writeln("<b><a href='"+item[1]+"' target='_blank'>"+item[0]+"</b></a> (Last modified: "+item[2]+")<br/><br/>"); // write result 
 
     
 
     } 
 
     document.writeln("End of results..."); 
 
     }

Verwandte Themen