cancel
Showing results for 
Search instead for 
Did you mean: 

FiledownloadresourcePath

Former Member
0 Kudos

if i have a webdynpro project that have file upload and download feature

when i click upload the file will store in directory specify by me,

later on...when i try to download the file....

how to the system know which directory i stored......

or the system will only retrieve from specific location ?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

You will have to specifiy the location from which the file has to be downloaded.

In your case snce you have uploaded the file to a specific location, you can give the same location to read the file for download.

Former Member
0 Kudos

normally it will store in this location right...


localhost\d$\usr\sap\N01\DVEBMGS01\j2ee\cluster\server0

something very weird happen...

when i try my run my webdynpro locally...it can export successfully...it will prompt me to download

when i run in the http://xxx.com/webdynpro/MailApp

it cannot export the file....the external window popup and close back

[code]

try {

final byte[] content = this.getByteArrayFromResourcePath("OutboundMail.xls");

//final byte[] content = this.getByteArrayFromResourcePath("

localhost
d$
usr
sap
N01
DVEBMGS01
j2ee
cluster
server0
tm.xls");

final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.XLS);

resource.setResourceName("MailOutbound_Report_Summary");

try {

final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getAbsoluteURL(), "WD_Filedownload", false);

// wdComponentAPI.getMessageManager().reportSuccess("resourcePath"+resource.getAbsoluteURL());

window.open();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

private byte[] getByteArrayFromResourcePath(String resourcePath)

throws FileNotFoundException, IOException {

FileInputStream in = new FileInputStream(new File(resourcePath));

ByteArrayOutputStream out = new ByteArrayOutputStream();

int len;

byte[] part = new byte[10 * 1024];

while ((len = in.read(part)) != -1) {

out.write(part, 0, len);

}

in.close();

return out.toByteArray();

}

public Map DownloadToExcel(ArrayList columnInfos1,String type)

{

byte[] b = null;

String linktoFile = null;

StringBuffer err = new StringBuffer();

StringBuffer xml_file = new StringBuffer();

int noofelem = wdTableNode.size();

ArrayList columnInfos = trimHeaderTexts(columnInfos1);

String nodename = wdTableNode.getNodeInfo().getName().trim();

String _nodename = nodename.substring(0, 1).toUpperCase()+nodename.substring(1).toLowerCase();

xml_file.append("<?xml version='1.0' encoding='UTF-8' standalone='no'?><")

.append(_nodename)

.append(">\n");

int size = columnInfos.size();

for(int i =0;i<noofelem;i++){

IWDNodeElement elem = wdTableNode.getElementAt(i);

xml_file.append("<")

.append(_nodename)

.append("Element>");

for (int j = 0;j<columnInfos.size();j++)

{

String attributeName = (String)columnInfos.get(j);

xml_file.append("<")

.append(attributeName)

.append(">")

.append(elem.getAttributeValue(attributeName))

.append("</")

.append(attributeName)

.append(">\n");

}

xml_file.append("</")

.append(_nodename)

.append("Element>\n");

}

xml_file.append("</")

.append(_nodename)

.append(">\n");

try {

//modify here

if (type=="MailInbound"){

FileOutputStream fout=new FileOutputStream("tm.xml");

OutputStreamWriter out=new OutputStreamWriter(fout,"UTF-8");

out.write(xml_file.toString());

out.flush();

out.close();

File xmlDocument = new File("tm.xml");

generateInboundMailExcel(xmlDocument);

}else if(type=="MailOutbound"){

FileOutputStream fout=new FileOutputStream("OutboundMail.xml");

OutputStreamWriter out=new OutputStreamWriter(fout,"UTF-8");

out.write(xml_file.toString());

out.flush();

out.close();

File xmlDocument = new File("OutboundMail.xml");

generateOutboundMailExcel(xmlDocument);

}

//b = xml_file.toString().getBytes("UTF-8");

// IWDCachedWebResource xlfile = WDWebResource.getWebResource(b,WDWebResourceType.XLS);

//xlfile.setResourceName(wdTableNode.getNodeInfo().getName()+" List");

//linktoFile = xlfile.getURL();

//System.err.println("Link To Url: " +linktoFile);

} catch (WDURLException e1) {

err.append(""+e1.getCause());

}catch (UnsupportedEncodingException e) {

err.append(""+e.getCause());

}catch(IOException e){

System.err.println("IOException:" +e.getMessage());

}

// Map m = new HashMap();

// m.put("data",b);

// m.put("url",linktoFile);

// m.put("error",""+err.toString());

// System.err.println("Hash Map:" +m.toString());

// return m;

}

public static void generateInboundMailExcel(File xmlDocument) {

try {// Creating a Workbook

HSSFWorkbook wb = new HSSFWorkbook();

HSSFSheet spreadSheet = wb.createSheet("spreadSheet");

spreadSheet.setColumnWidth((short) 0, (short) (256 * 25));

spreadSheet.setColumnWidth((short) 1, (short) (256 * 25));

// Parsing XML Document

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(xmlDocument);

System.err.println("tableemailinelement");

NodeList nodeList = document.getElementsByTagName("TablesemailinElement");

//Create font style

HSSFFont font=wb.createFont();

font.setFontHeightInPoints((short)10);

font.setFontName("Verdana");

font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

HSSFCellStyle style=wb.createCellStyle();

style.setFont(font);

// Creating Rows

System.out.println("create row");

HSSFRow row = spreadSheet.createRow(0);

HSSFCell cell = row.createCell((short) 0);

cell.setCellValue("DATE IN");

cell.setCellStyle(style);

cell = row.createCell((short) 1);

cell.setCellValue("EMAIL ID");

cell.setCellStyle(style);

cell = row.createCell((short) 2);

cell.setCellValue("SUBJECT");

cell.setCellStyle(style);

cell = row.createCell((short) 3);

cell.setCellValue("DATE RECEIVED");

cell.setCellStyle(style);

cell = row.createCell((short) 4);

cell.setCellValue("ACK DELIVERY");

cell.setCellStyle(style);

cell = row.createCell((short) 5);

cell.setCellValue("DATE ACK");

cell.setCellStyle(style);

cell = row.createCell((short) 6);

cell.setCellValue("SENDER");

cell.setCellStyle(style);

cell = row.createCell((short) 7);

cell.setCellValue("RECEIPIENT");

cell.setCellStyle(style);

for(int i=0;i<nodeList.getLength();i++){

System.err.println("loop: node" );

HSSFRow rowno=spreadSheet.createRow(i+1);

HSSFCellStyle cellStyle = wb.createCellStyle();

cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);

cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);

cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

//***********take note for string and date*************

cell = rowno.createCell((short) 0);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("dateIn").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 1);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("emailId").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 2);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("subject").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 3);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("dateReceive").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 4);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("ackDelivery").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 5);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("dateAck").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 6);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("sender").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 7);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("receipient").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

}

// Outputting to Excel spreadsheet

System.err.println("Outputing");

FileOutputStream output = new FileOutputStream(new File("tm.xls"));

wb.write(output);

output.flush();

output.close();

// byte[] bs = new byte[(int) xmlDocument.length()];

// IWDCachedWebResource xlfile = WDWebResource.getWebResource(bs,WDWebResourceType.XLS);

// xlfile.setResourceName("Report");

} catch (IOException e) {

System.out.println("IOException " + e.getMessage());

} catch (ParserConfigurationException e) {

System.out

.println("ParserConfigurationException " + e.getMessage());

} catch (SAXException e) {

System.out.println("SAXException " + e.getMessage());

}

}

public static void generateOutboundMailExcel(File xmlDocument) {

try {// Creating a Workbook

HSSFWorkbook wb = new HSSFWorkbook();

HSSFSheet spreadSheet = wb.createSheet("spreadSheet");

spreadSheet.setColumnWidth((short) 0, (short) (256 * 25));

spreadSheet.setColumnWidth((short) 1, (short) (256 * 25));

// Parsing XML Document

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(xmlDocument);

System.err.println("tableemailoutelement");

NodeList nodeList = document.getElementsByTagName("TablesemailoutElement");

//Create font style

HSSFFont font=wb.createFont();

font.setFontHeightInPoints((short)10);

font.setFontName("Verdana");

font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

HSSFCellStyle style=wb.createCellStyle();

style.setFont(font);

// Creating Rows

System.out.println("create row");

HSSFRow row = spreadSheet.createRow(0);

HSSFCell cell = row.createCell((short) 0);

cell.setCellValue("DATE IN");

cell.setCellStyle(style);

cell = row.createCell((short) 1);

cell.setCellValue("EMAIL ID");

cell.setCellStyle(style);

cell = row.createCell((short) 2);

cell.setCellValue("SUBJECT");

cell.setCellStyle(style);

cell = row.createCell((short) 3);

cell.setCellValue("ACK DELIVERY");

cell.setCellStyle(style);

cell = row.createCell((short) 4);

cell.setCellValue("DATE SENT");

cell.setCellStyle(style);

cell = row.createCell((short) 5);

cell.setCellValue("SENDER");

cell.setCellStyle(style);

cell = row.createCell((short) 6);

cell.setCellValue("RECEIVER");

cell.setCellStyle(style);

for(int i=0;i<nodeList.getLength();i++){

System.err.println("loop: node" );

HSSFRow rowno=spreadSheet.createRow(i+1);

HSSFCellStyle cellStyle = wb.createCellStyle();

cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);

cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);

cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);

cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

//**********************take note for the cell date and string*************************

cell = rowno.createCell((short) 0);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("dateIn").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 1);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("emailId").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 2);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("subject").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 3);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("ackDelivery").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 4);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("dateSend").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 5);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("sender").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

cell = rowno.createCell((short) 6);

cell.setCellValue(((Element) (nodeList.item(i)))

.getElementsByTagName("receipient").item(0)

.getFirstChild().getNodeValue());

cell.setCellType(HSSFCell.CELL_TYPE_STRING);

}

// Outputting to Excel spreadsheet

System.err.println("Outputing");

FileOutputStream output = new FileOutputStream(new File("OutboundMail.xls"));

wb.write(output);

output.flush();

output.close();

// byte[] bs = new byte[(int) xmlDocument.length()];

// IWDCachedWebResource xlfile = WDWebResource.getWebResource(bs,WDWebResourceType.XLS);

// xlfile.setResourceName("Report");

} catch (IOException e) {

System.out.println("IOException " + e.getMessage());

} catch (ParserConfigurationException e) {

System.out

.println("ParserConfigurationException " + e.getMessage());

} catch (SAXException e) {

System.out.println("SAXException " + e.getMessage());

}

}

[/code]

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Abhinav_Sharma
Contributor
0 Kudos

Hi

The you have not mentioned the file directory. The other way is to create a dir in ur server where you can handle ur files. for e.g : u can create file in ur C directory as

FileInputStream in = new FileInputStream(new File("C:
" + resourcePath));

and then u can retrieve the file.

Abhinav

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

All you have done is expose your application to Internet using Web Dispatcher isnt it? If your application is visible, the download shouldnt be a problem. Please try the code snippet that I have sent to you.

Regards,

Leena

Former Member
0 Kudos

Hi,

I understand that you are using the FileDownload UI element of WebDynpro. This UIelement appears as a link, on click of which the file gets downloaded. Here is how the download functionality has to be coded

Insert the File Download UI element into the View.

The File Download UI element has various properties out of which only the data property is bindable and mandatory.

Bind this property to a context attribute of type binary.(Lets call the attribute filedata)

The file to be downloaded will be stored in this attribute.

The File Download element will be active only if there is data in the above attribute.

We have to write the file to be downloaded to the attribute.

Lets now look into the coding part how this can be achieved.

Consider that you have created a value attribute “filedata” of type binary in the context of the view. Also consider that the name of the file in server is “test.doc”.At this moment the attribute does not have any data.

try

{

File input = new File("C:
test.doc");

int length =(int)input.length();

//Create a byte array b to hold the file

byte b[] = new byte[length];

FileInputStream in = new FileInputStream(input);

//Reading the file to a byte array b

in.read(b);

in.close();

//Setting the data from the byte array to the context element.

wdContext.currentContextElement().setfiledata(b);

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportSuccess("Error in File

IO"+ex.toString());

}

// Structure information of the context attribute

IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("filedata");

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attinfo.getModifiableSimpleType();

// Default File name which appears when opened on client machine

binaryType.setFileName("testing.doc");

//Explicitly setting the file type

binaryType.setMimeType(WDWebResourceType.DOC);

Kindly revert back if you have doubts.

Thanks and regards

Leena

Former Member
0 Kudos

something i want to highlight here.....

actually i can successfully download the file with popup external windows when it is locally...means....localhost/webdynpro/MailApp

BUT

not when i published out for public to access http://xxx/webdynpro/MailApp

Any reason...for this ?

Or my coding is wrong...