Skip to Content

Creating folders in KM dynamically

        The following code illustrates how to create folders in Knowledge Management using Webdyno APIs.This comes as an extension of the weblog I posted earlier ie for uploading files to KM repository . If you want to classify the documents uploaded in KM into specific folders at runtime.

  IWDClientUser wdClientUser = WDClientUser.getCurrentUser(); sapUser = wdClientUser.getSAPUser();
  //create an ep5 user from the retrieved user IUser ep5User =WPUMFactory.getUserFactory().getEP5User(sapUser);
  ResourceContext context = new ResourceContext(ep5User);
  RID rid = RID.getRID(wdContext.currentContextElement().getPath());
  IResourceFactory factory = ResourceFactory.getInstance();
  //get an instance of the current folder under which we have to create subfolders ICollection folder = (ICollection)factory.getResource(rid,context);
  ICollection newfolder = folder.createCollection(newFolderName,null,null);

      This createCollection() will create a new collection and additional system resources the collection needs.This newFolderName specifies the name of the new folder to be created.

You must be Logged on to comment or reply to a post.
  • Hi Rohit,

        We need to extract content from KM through a webdynpro appliction. The following code is working for extracting content which is saved in text format.
             IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
     sapUser = wdClientUser.getSAPUser();
    //                         create an ep5 user from the retrieved user
              IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
              IResourceContext context = new ResourceContext(ep5User);
                          /*Specify the path of ur document here.*/
              //RID pathRID = RID.getRID("/documents/70f51182-84c3-2710-ce91-8d5fbfde713d.xml");
              RID pathRID = RID.getRID("/documents/hol.txt");

              IResource resource = ResourceFactory.getInstance().getResource(pathRID, context);                    
              InputStream in = resource.getContent().getInputStream();
              ByteArrayOutputStream out = new ByteArrayOutputStream();
              byte[] buffer = new byte[4096];
              int bytesread = 0;
              while ((bytesread = != -1)
                   out.write(buffer, 0, bytesread);
              String myData = out.toString();
                             /**myFile will containS the content of the document.*/
                        //     wdComponentAPI.getMessageManager().reportSuccess(myData);
         //wdContext.currentContextElement().setSetDisp(" Hello Srinivas ");
         catch (Exception e)
           // wdContext.currentContextElement().setTextdisp("IO Error:" + e.getMessage());
        When we are trying to extract content saved in .xml file, the content is not getting extracted. Instead, the KM path is getting displayed in the webdynpro application.

    Can you please help us out, how to extract content from KM which is saved in .xml file??

    Thanks much in advance,

    • hi Sunitha,
      First try to see if you can open the documents through webdynpro.Then we can see where the error comes


      • hi sunitha,
        get an instance of window class and open it
        IWDWindow window =



        + "/documents/Public Documents/...."


        "from km repository",


    • I need to upload data from the flat file( which consists of cost centers data) into internal table (which i can do with WS_UPLOAD or GUI_UPLOAD this is not a problem).
         here in the flat file, there are 50 different cost centers... so after uploading into internal table i need split the data based on cost center wise and need to create 50 Cost Center folders dynamically in portal server and place each cost center data file seperately in corresponding cost center folder.
      As i need to deliver it soon, i really appreciate if you can give me the solution ASAP.

      Thank You Very Very Much in advance.
      • Hi,

        Since you are using the portals passing data from excel to KM you can do it easilly

        add POI.jar

        By using the POI package in java you can read a xls file

        You can access the data inside the excel sheet like this

        POIFSFileSystem fs      =
                    new POIFSFileSystem(new FileInputStream("workbook.xls"));
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            HSSFRow row = sheet.getRow(2);
            HSSFCell cell = row.getCell((short)3);

        After that you have to make a java class containing

        all the fields

        make a vector to store these objects of a particular cost center

        also make a hashmap to store the key and the cost center vectors

        Once you get all the fields you can create the folders dynamically