Skip to Content
avatar image
Former Member

Save XML/(Any file) in server file system

Hello folks!

Does some one know how to save xml file on server side from WebDynpro app. Imagine that you have some data that want to put into xml file and afterward to save that file in server file system? Actually is there neccessary to have some police file in order to access to local file system? Thanks in advance for your time, effort and attention.

Aleksandar

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 25, 2007 at 10:37 AM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 24, 2007 at 08:34 PM

    Hi

    In my opinion the best way for this mission is using KM and KM API.

    You can create a file system repository in KM for the directory in which you want to upload the file.

    For your convenient I add a code sample for uploading file to KM:

    public void onActionDone(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

    {

    //@@begin onActionDone(ServerEvent)

    if (wdContext.currentContextElement().getFileSource() != null){

    //wdContext.currentContextElement().setPrintStr(wdContext.currentContextElement().getFileSource().toString());

    try {

    IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

    com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();

    //create an ep5 user from the retrieved user

    IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);

    //Context.currentContextElement().setPrintVal1("***"+sapUser.toString());

    //establish resource context */

    IResourceContext resourceContext = new ResourceContext(ep5User);

    //get a resource factory

    IResourceFactory resourceFactory = ResourceFactory.getInstance();

    //get a RID from the current path to display the according content

    RID pathRID = RID.getRID("/documents/Public Documents/yoel_test/");

    //get a Iresource object to work on

    IResource resource = resourceFactory.getResource(pathRID, resourceContext);

    //cast the object to a Collection

    ICollection collection = (ICollection) resource;

    ByteArrayInputStream datastream = new ByteArrayInputStream (wdContext.currentContextElement().getFileSource());

    //FileInputStream file = new FileInputStream(wdContext.currentContextElement().getFilePath());

    FileDataSource fileSr = new FileDataSource (wdContext.currentContextElement().getFilePath());

    wdContext.currentContextElement().setPrintStr(fileSr.getContentType());

    String mimetype = "";

    //IContent content = new Content (datastream,fileSr.getContentType(),datastream.available());

    if (wdContext.currentContextElement().getFilePath().toLowerCase().endsWith("doc")){

    mimetype = "application/msword";

    }

    IContent content = new Content (datastream,mimetype,datastream.available());

    collection.createResource(wdContext.currentContextElement().getFilePath(),null,content);

    }

    catch (Exception e) {

    wdContext.currentContextElement().setPrintStr(e.toString());

    e.printStackTrace();

    }

    }

    //@@end

    }

    Add comment
    10|10000 characters needed characters exceeded