1

It’s easy to do file deletion operation in LotusScript using Kill Statement. How to achieve the same thing in XPages using SSJS?

I tried below code but nothing happened:

var file:java.io.File = new java.io.File("FilePath");
file.getClass().getMethod("delete", null).invoke(file, new java.lang.Object[0]);
Naveen
  • 6,786
  • 10
  • 37
  • 85
Prabhakar
  • 402
  • 6
  • 20
  • 1
    As the luck of the draw 'delete' is reserved in javascript. I would recomend you to use a java class to delete your file wich you can direct call from your SSJS like this: http://stackoverflow.com/questions/16692194/do-i-really-need-a-managed-bean/16694026#16694026 – Michael Saiz Aug 27 '13 at 10:58
  • 3
    Have you [added the XPage signer to the field on the server document that identifies users who are allowed to run restricted operations](http://stackoverflow.com/a/15225133/1047998). Also the second line of your code can simply be written as `file.delete()`. And I would recommend using Java class rather than SSJS. – Naveen Aug 27 '13 at 11:06
  • @Michael: Thanks, will write a java class. – Prabhakar Aug 27 '13 at 11:50
  • @Naveen: Thanks for the suggestion, I haven't added XPage signer. and file.delete() throws compile time error "Encountered delete, was expecting " – Prabhakar Aug 27 '13 at 11:53
  • 3
    As Michael said, delete is a reserved word in JavaScript. So it's expecting to be passed a variable to delete, not understanding that `delete` in this instance is a method of your `file` Java object. Because SSJS isn't really Java. It becomes Java at runtime, but if you don't follow JS rules during development, Designer won't let it become Java. This is one of many reasons SSJS shouldn't even exist. Just use Java. – Tim Tripcony Aug 27 '13 at 13:15
  • I wrote below java code but was not useful, my nsf file is on local do I still need to add XPage signer field on the server document? pls let me know if I am missing or doing something wrong. `public static void deleteAttachment(String filePath) { // Delete file attachment File f = new File(filePath); f.delete(); }` – Prabhakar Aug 27 '13 at 13:40
  • See http://stackoverflow.com/questions/1729049/how-to-tell-why-a-file-deletion-fails-in-java for how to troubleshoot – Egor Margineanu Aug 27 '13 at 14:19
  • 3
    You can call it as an array in SSJS: *file["delete"]();* – Sven Hasselbach Aug 27 '13 at 14:49

0 Answers0