cancel
Showing results for 
Search instead for 
Did you mean: 

Can't open document in KM

Abhinav_Sharma
Contributor
0 Kudos

Hi all

I am new to KM and written a test application which displays <b>doc</b> files of the repository and when i click any of the file it should display its content.

The first part is ok but I'm facing problem in second part. I don't know how to retrieve contents of the file.

Can u anyone plz help me what are the steps required for retrieving the contents?

Any help appreciated

Abhinav

Accepted Solutions (0)

Answers (4)

Answers (4)

Abhinav_Sharma
Contributor
0 Kudos

Hi Julian,

Can u elaborate ur point in more detail.

Former Member
0 Kudos

Which part? The one about legal URIs, or the one about how to produce them? For the latter, see https://media.sdn.sap.com/javadocs/NW04/SPS15/km/com/sapportals/wcm/service/urlgenerator/IURLGenerat....

Best regards, Julian

Abhinav_Sharma
Contributor
0 Kudos

Thanks Akhilesh

Its really very helpfull. Points rewarded. I have some doubts regarding Knowledge Management...

Can u plz tell me when & where to use IContent & InputStream?

Correct me If I'm wrong, we can use this when we create files in the repository?

How can I edit the contents and then save it back to repository?

Also, one more thing how can we upload a file into repository?

former_member394902
Contributor
0 Kudos

Hi Abhinav,

Can u plz tell me when & where to use IContent & InputStream?

>> You use IContent and IResource when you want to create a KM resource and upload the content programmatically.

Correct me If I'm wrong, we can use this when we create files in the repository?

How can I edit the contents and then save it back to repository?

>> if the resource is already there in KM, you can use the "edit locally" functionality of KM to edit the content and then upload the docu back into KM

Also, one more thing how can we upload a file into repository?

>> using the standard KM UI. If using your own application then you need to use IResource and IContent to upload a file into KM.

Hope this helps.

Akhilesh

Abhinav_Sharma
Contributor
0 Kudos

Thanks Akhilesh for responding so fast.

Below is what I tried to retrieve the content:

path : stores the path to the folder in KM

getObject : gives the name of the file to be retrieved

ResourceContext ctx = new ResourceContext(usrEP5);

RID rid = RID.getRID(wdContext.currentContextElement().getPath() "/"wdContext.currentTableElement().getObject());

IResource res = ResourceFactory.getInstance().getResource(rid, ctx);

try {

IContent con = res.getContent();

InputStream in = con.getInputStream();

// byte b[] = new byte[(int) con.getContentLength()];

in.read();

String CompPath = "http://sap2:50000/irj/servlet/prt/portal/prtroot /com.sap.km.cm.docs/documents/RMT/Resumes"

+ rid.getPath().toString();

IWDWindow openwin = wdComponentAPI.getWindowManager ().createExternalWindow(CompPath,"win1",true);

openwin.open();

} catch (ContentException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

former_member394902
Contributor
0 Kudos

Hi Abinav,

Every doc in KM has a access link. From what i could make out of your code is, given a file name, you want to open the file in a new window. and you already know the root folder path e.g. if the doc resides in /docuemnts/public docuemnts/resumes and the user enters Abhinav.doc you need to open this in a new window corect?

Then replace this piece of your code


String CompPath = "http://sap2:50000/irj/servlet/prt/portal/prtroot /com.sap.km.cm.docs/documents/RMT/Resumes"
+ rid.getPath().toString();

with


String compPath = "http://sap2:50000/irj/go/km/docs/" + rid + filename

You do not need to explicitly read the content. Give this KM file access linnk tothe new window and it will take care of the rendering.

Hope this helps.

Akhilesh

Former Member
0 Kudos

Note that generating URIs by pasting in RIDs does not work reliably (URIs may not contain non-ASCII characters, for instance).

Please use the various methods provided by the URLGeneratorService instead...

former_member394902
Contributor
0 Kudos

Hi Abhinav,

Can you let us know what code have you written and how are you trying to read the content? Are you using IResource and IContent? Look for these API's in the javadocs http://www.sdn.sap.com/irj/sdn/javadocs

Akhilesh