Foros de discusión
Adding a new document
Jack Palm, modificado hace 8 años.
Adding a new document
Junior Member Mensajes: 28 Fecha de incorporación: 13/04/15 Mensajes recientes
I have some code here, trying to add a new document into documents and media for my group. But, I have a few problems with this:
1. It sais "Cannot instantiate the type File" when I try:
java.io.File file = new File("\\\\ska\\home$\\JacksPlace\\476361\\Desktop\\Jacks mapp\\sa.pdf");
2. I thought I were supposed to use my File object with FileInputStream:
fis = new FileInputStream("\\\\ska\\home$\\JacksPlace\\476361\\Desktop\\Jacks mapp\\sa.pdf");
instead of the search path which is there right now.
3. The "file" uploaded only becomes a draft and there is no file.
4. I just cant understand how to instantiate the map - object or what this is for?
Many questions but I would realy appreciate if someone wanted to post an example of their code for how to do this I have followed this documentation:
https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portlet/documentlibrary/service/DLFileEntryLocalServiceUtil.html
My code so far:
1. It sais "Cannot instantiate the type File" when I try:
java.io.File file = new File("\\\\ska\\home$\\JacksPlace\\476361\\Desktop\\Jacks mapp\\sa.pdf");
2. I thought I were supposed to use my File object with FileInputStream:
fis = new FileInputStream("\\\\ska\\home$\\JacksPlace\\476361\\Desktop\\Jacks mapp\\sa.pdf");
instead of the search path which is there right now.
3. The "file" uploaded only becomes a draft and there is no file.
4. I just cant understand how to instantiate the map - object or what this is for?
Many questions but I would realy appreciate if someone wanted to post an example of their code for how to do this I have followed this documentation:
https://docs.liferay.com/portal/6.2/javadocs/com/liferay/portlet/documentlibrary/service/DLFileEntryLocalServiceUtil.html
My code so far:
public void addFile(ActionRequest request, ActionResponse response){
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long realUserId = themeDisplay.getRealUserId();
long groupId = themeDisplay.getLayout().getGroupId();
ServiceContext serviceContext = new ServiceContext();
serviceContext.setScopeGroupId(groupId);
java.io.File file = null;
FileInputStream fis = null;
try {
fis = new FileInputStream("\\\\ska\\home$\\JacksPlace\\476361\\Desktop\\Jacks mapp\\sa.pdf");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
Map<string, fields> fieldsMap = new HashMap<string, fields>();
try {
DLFileEntryLocalServiceUtil.addFileEntry(realUserId, groupId, groupId, 0, "", "", "AnotherFile", "A new file", "", 0, fieldsMap, file, fis, 396, serviceContext);
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}
}
</string,></string,>
Byrån Zaugg, modificado hace 8 años.
RE: Adding a new document
Expert Mensajes: 252 Fecha de incorporación: 6/04/12 Mensajes recientes
Jack Palm, modificado hace 8 años.
RE: Adding a new document
Junior Member Mensajes: 28 Fecha de incorporación: 13/04/15 Mensajes recientes
Sorry about that, will do so