cancel
Showing results for 
Search instead for 
Did you mean: 

Reading txt file from KM

Former Member
0 Kudos

I have a file located in KM that I wanted to read, and based on the content (numbers - one on each line), I create my logic of what to display. I have read a lot of the threads and blogs on how to connect and read from KM, but I seems like I can't get to the document.

Whenever I try to deploy the code to test, my DTR rejects it because it doesn't find the .JAR's even though I've added them according to the document "Using Knowledge Management Functionality in Web Dynpro Applications"

Could someone point to a good document to go to or something? What are the steps to go though for accessing a document in KM?

Thank you.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

I did look at the document and yes, I am referencing the km in shared references.

Former Member
0 Kudos

Thank you for the code, but my trouble is not the code, I can get that and it works on my local machine(somewhat). When I test my code on my local machine, its signing in to KM as "Guest", so, I need to test on the portal, but when I go to deploy my code, DTR wont let me activate it because it can't find the .Jar files I'm using. And I did set up an external library dc, and I am referencing it in the "used dc" portion of my DC. What I can't understand is why it wont find the .jar files, and if I'm missing something.

Former Member
0 Kudos

Hi,

I didn't understand why you are not able to actiavte it.

I have also created an external library DC for this KM API Jars and added this jars to public parts both for compile time and run time, and used this public parts in my webdynpro DC....

I have given the sharing reference in my webdynpro DC : PORTAL:sap.com/com.sap.km.application

Its working for me...

But for external libraries check wether you have followed all the steps mentioned in this blogs..

/people/bala.krishnan2/blog/2006/09/25/bid-adieu-to-bots--using-captchas

/people/bertram.ganz/blog/2008/11/24/how-to-use-external-jar-files-in-web-dynpro-development-components

Go through this blog also...

/people/rohit.radhakrishnan/blog/2005/05/27/uploading-files-to-km-repository-using-webdynpro-apis

Regards,

Saleem

Former Member
0 Kudos
Former Member
0 Kudos

What I need is something like this to work:

RID rid = RID.getRID("/documents/testext.txt");
try { 
     com.sapportals.wcm.repository.IResource resource = ResourceFactory.getInstance().getResource(rid, resourceContext);
if (resource != null) {
String text = "";
BufferedReader in = new BufferedReader(new InputStreamReader(resource.getContent().getInputStream()));
while ((text = in.readLine()) != null) {
wdContext.currentTextElement().setText(text);
}
}
} catch (RuntimeException e2) {
// TODO Auto-generated catch block
}

How can I get something like that to work? My file already exists in KM and I am using a DC.

pravesh_verma
Active Contributor
0 Kudos

Hi Sana,

Can you please try this code.


RID rid = RID.getRID("/documents/testext.txt");
try { 
     com.sapportals.wcm.repository.IResource resource = ResourceFactory.getInstance().getResource(rid, resourceContext);
if (resource != null) {
String str = null;
String text = "";

BufferedReader in = new BufferedReader(new InputStreamReader(resource.getContent().getInputStream()));
while ((str = in.readLine()) != null) {
text+ =  str+"\n";
}
wdContext.currentTextElement().setText(text);
}
} catch (RuntimeException e2) {
// TODO Auto-generated catch block
}

I hope this should solve your issues. Please revert back in case you need any further help on this.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi,

Are you working in Development Component?

Because if so you might need to create an External Library DC for the jars that you need to add and then add them as Used DC to your current DC.

Refer to the following link:

http://help.sap.com/saphelp_nw04s/helpdata/en/5a/2e2f4234135433e10000000a155106/content.htm

Regards.

Rajat

Former Member
0 Kudos

>

> Hi,

>

> Are you working in Development Component?

> Because if so you might need to create an External Library DC for the jars that you need to add and then add them as Used DC to your current DC.

>

> Refer to the following link:

> http://help.sap.com/saphelp_nw04s/helpdata/en/5a/2e2f4234135433e10000000a155106/content.htm

>

> Regards.

> Rajat

I've gone through this document before, but my DTR still rejects it when I try to activate it.