12/11/2010

How to create a link to a document in Liferay

One thing I really often had to do was to provide download links to documents.
There were always people who didn´t wanted to browse through the portal.

So ... here is the solution:


public String createDocumentLink(DLFileEntry fileEntry) {


long folderId = fileEntry.getFolderId();
String filename = fileEntry.getName();


StringBuilder builder = new StringBuilder();
builder.append(themeDisplay.getPortalURL());
builder.append(themeDisplay.getPathMain());
builder.append("/document_library/get_file?folderId=");
builder.append(folderId);
builder.append("&name=");
builder.append(filename);


String result = builder.toString();
return result;
}


That´s all :) Now you can directly point to a document you uploaded.


If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.