cancel
Showing results for 
Search instead for 
Did you mean: 

does KM file exist ?

Former Member
0 Kudos

Hi,

I would like to test if a km file exists but cannot make it work. I have the following code:

String numLiv = "http://<server>:<port>/irj/go/km/docs/MyRepository/myFile.pdf";
java.io.File myFile = new File(numLiv);
	if (myFile.isFile()) {
		wdContext.currentContextElement().setPath(numLiv);
		messageMgr.reportSuccess("Mon fichier existe !!");
	}

I have no idea what is wrong, I also tried with myFile.exists() but every time it returns false. Th efile do exist in my KM.

Thank you for your help.

Thibault Schalck

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Did You try this code:

URL url = new URL( "http://<server>:<port>/irj/go/km/docs/MyRepository/myFile.pdf" );
URLConnection urlConn = url.openConnection();
urlConn.setDoInput( true );
InputStream stream = urlConn.getInputStream();
//stream.available(); do sth with stream, eg. write to local file,
stream.close();

Or, the better way, you should use Repostiory Framework API :

com.sapportals.portal.security.usermanagement.IUser user= 
     WPUMFactory.getUserFactory().getEP5User( WDClientUser.getCurrentUser().getSAPUser() );
RID rid = RID.getRID( "/MyRepository/myFile.pdf" );
ResourceContext resourceContext = new ResourceContext( user );
if ( ResourceFactory.getInstance().checkExistence( rid, resourceContext ) == true ) {
//document exists!.
}

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sapportals.km.docs/library/content-manage...

Hope it helps

Jakub Krecicki

Former Member
0 Kudos

Thanks for the helpful answer Jakub Krecicki, I just gave you 10 points !!

Answers (1)

Answers (1)

ravindra_bollapalli2
Active Contributor
0 Kudos

hi

check this

/people/community.user/blog/2008/09/03/how-to-download-km-documents-using-web-dynpro-java

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/05c7e2ae-0a01-0010-ca98-fe42dbe0...

https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/aef1a890-0201-0010-6faf-8fa09480...

let me know am i reached u r problem

bvr