import lotus.domino.*; import java.io.File; public class JavaAgent extends AgentBase { Database db; String formName = "Document"; String startPath = "d:\\import"; public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); db = agentContext.getCurrentDatabase(); File startDirectory = new File(startPath); doScan(startDirectory); } catch(NotesException e) { e.printStackTrace(); } } // ALL YOUR STACK ARE BELONG TO ME public void doScan(File directory) { String[] files = directory.list(); for (int i = 0; i < files.length; i++) { File ourFile = new File(directory + "\\" + files[i]); if(ourFile.isDirectory()){ doScan(ourFile); } else { doImport(ourFile); } } } public void doImport(File ourFile) { String importName = ourFile.getAbsolutePath(); System.out.println("Importing file:" + importName); try{ // this should be done "properly" String categoryName = ourFile.getParent().substring(10) ; Document doc = db.createDocument(); doc.replaceItemValue("Subject", ourFile.getName()); doc.replaceItemValue("Categories", categoryName); doc.replaceItemValue("Form", formName); RichTextItem body = doc.createRichTextItem("Body"); body.appendText(""); body.addNewLine(2); body.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, importName, importName); doc.save(true, true); } catch(NotesException e) { System.out.println(e.id + " " + e.text); e.printStackTrace(); } } }