Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

how to upload a file into specified location

Hi Frndz..

How to upload a file using File upload feature in web dynpro into our specified location(usr/sap/Images/....),not into workspace r default path in server.

Thanks in Advance

Regards

Rajesh

replied

Hi Rajesh,

Use below code on your "Upload" Action:


	try
	{
// Give full path of folder on server where you want to upload the file. 

		File file = new File("D:\\usr\\sap\\Images\\"+wdContext.currentContextElement().getResource().getResourceName().toString());

// D:\usr\sap\Images folder should present on server
		FileOutputStream op = new FileOutputStream(file);
		
		if(wdContext.currentContextElement().getResource()!=null)
		{
			text=wdContext.currentContextElement().getResource().read(false);
				while((temp=text.read())!=-1)
				{
					op.write(temp); 
				}
		}
		op.flush();
		
		op.close();
		
	}

	catch(Exception e)
	{
		wdComponentAPI.getMessageManager().reportSuccess("Error while uploading file : "+e.getMessage());
	}


Thanks

Sandy

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question