on 06-07-2011 8:44 AM
Hi,
I have a requirement in our project to read a multi line, semi column delimited flat from kept on the Knowledge Management repository and display the contents in the Portal.
I had tried couple of options and was unable to read the file. I am not sure which are the correct APIs I should be using.
Can any one of the experts could guide me with the sample code, that will be great!
Your early response is highly appreciated.
Regards
Venkat
here you go.
//******* Read file from KM
String repository_km;
String FileURL;
repository_km="/documents/data/data.txt";
try
{
//Getting the user......
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
//Getting the Resource.........
IResourceContext resourseContext = new ResourceContext(ep5User);
IResourceFactory resourseFactory = ResourceFactory.getInstance();
//path to the KM Folder ("/documents/data/data.txt")
RID rid= RID.getRID(repository_km);
com.sapportals.wcm.repository.IResource resource =
resourseFactory.getResource(rid, resourseContext);
if (resource != null)
{
String text = "";
BufferedReader in = new BufferedReader(new InputStreamReader(resource.getContent().getInputStream()));
int count=0;
while ((text = in.readLine()) != null)
{
strText[count] =text;
count++;
}
}
}
catch (RuntimeException e2) {
wdComponentAPI.getMessageManager().reportException("Error in reading file from KM : "+e2.getMessage(),true);
// TODO Auto-generated catch block
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Do you get an exception, is the code unable to locate your document, or is no data read at all?
Also, bear in mind the current user should have read permissions to the KM file.
Although John's code seem somewhat incomplete (the string fileURL is never used and the file's content is apparently stored in a yet undeclared string array strText) in essence in should work and you should be able to iron out these glitches yourself
Cheers,
Robin
Hi Robin,
Thanks for your response.
Yes, I have taken care of those missing parts. But, still it is not working. I am not getting any detailed error message either.
It was failing while getting the RID object.
RID rid = RID.getRID("/documents/testdata.txt");
Application is failing at the execution of this statement. But it is not giving any error message.
I tried keeping the file in the KM repository, shared drive on my own desktop, but still it is not working.
Any idea why it is failing.
Early response is highly appreciated.
Regards
Venkat
Hi John,
I was trying to debug the program.
It was failing at the following statement but not giving any detailed error message. It was in the try catch block and going to catch exception bloc when trying to execute the statement.
RID rid = RID.getRID("/documents/testdata.txt");
Any idea why it is failing at this stage?
Regards
Venkat
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.