Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Carleen Dickerson
Re: [Liferay Forums][6. Portal Framework] RE: Having problems integrating w
April 10, 2013 10:25 AM
Answer

Carleen Dickerson

Rank: New Member

Posts: 9

Join Date: March 12, 2013

Recent Posts

I'm sorry but I don't understand how this helps me.

On Wed, Apr 10, 2013 at 12:04 PM, Manish Yadav from liferay.com <
forums@liferay.com> wrote:

> Hi Carleen Might this code will help you
>
> *JSP*
> 1<script type="text/javascript">
> 2 function send()
> 3 {
> 4 document.UploadForm.submit();
> 5 }
> 6 </script>
> 7 <h3>Upload User Message:</h3>
> 8
> 9 <form name="UploadForm" action="<portlet:actionURL/>"
> enctype="multipart/form-data" method="POST">
> 10 <div class="center_button1">
> 11
> 12 <input type="file" name="fileName"
> size="50">&nbsp;&nbsp;&nbsp;
> 13
> 14 <button type="submit" name="Upload User Message"
> value="Upload User Message" class="button_no_background" title="Upload User
> Message" onClick="send()">
> 15 <img src="<%=
> request.getContextPath()%>/images/button_upload.gif" />
> 16 </button>
> 17 </div>
> 18 </form>
>
>
> *Action Class*
> 1
> 2 public void processAction(ActionRequest request, ActionResponse
> response) throws PortletException, IOException
> 3 {
> 4
> 5 realPath = getPortletContext().getRealPath("/");
> 6 System.out.println(realPath);
> 7
> 8 byte[] bytes = null;
> 9 PortletContext portletContext =
> request.getPortletSession().getPortletContext();
> 10 try{
> 11
> 12 UploadPortletRequest uploadRequest =
> PortalUtil.getUploadPortletRequest(request);
> 13 String sourceFileName
> =uploadRequest.getFileName("fileName");
> 14 File file = uploadRequest.getFile("fileName");
> 15 try {
> 16 bytes = FileUtil.getBytes(file);
> 17 } catch (IOException e2) {
> 18 e2.printStackTrace();
> 19 }
> 20 File newFile=null;
> 21 if ((bytes != null) && (bytes.length > 0)) {
> 22
> 23 try {
> 24 newFile = new
> File(realPath+"html/"+sourceFileName);
> 25 FileInputStream fileInputStream = new
> FileInputStream(file);
> 26 FileOutputStream fileOutputStream = new
> FileOutputStream(newFile);
> 27 fileInputStream.read(bytes);
> 28
> 29 String value = new String(bytes);
> 30
> 31 fileOutputStream.write(bytes, 0,
> bytes.length);
> 32 fileOutputStream.close();
> 33 fileInputStream.close();
> 34
> 35
> 36
> PoiReadExcelFile.xslFileReader(request,response,realPath+"html/",sourceFileName);
> 37 }
> 38 catch (FileNotFoundException e) {
> 39 System.out.println("File Not Found.");
>
> 40 e.printStackTrace();
> 41 }
> 42 catch (IOException e1){
> 43 System.out.println("Error Reading The File.");
> 44 e1.printStackTrace();
> 45 }
> 46 }
> 47
> 48 } catch (Exception e) {
> 49 e.printStackTrace();
> 50 }
> 51 }
>
>
> To view the thread, follow the link below:
>
> https://www.liferay.com/community/forums/-/message_boards/view_message/23517237
> --
> Thanks, Liferay.com Forums <http://https//www.liferay.com>




--
Carleen
Manish Yadav
RE: Re: [Liferay Forums][6. Portal Framework] RE: Having problems integrati
April 10, 2013 11:39 AM
Answer

Manish Yadav

Rank: Expert

Posts: 467

Join Date: May 26, 2012

Recent Posts

my apologies carleen......

Above solution is of some other post . i Copied wrongly in your thread.