on 05-24-2007 12:44 PM
Hiiiiii
I am working on a file upload and file download problem.
I have created a properties file and uploaded it on the server in C Drive..
and i have checked the server..File has been uploaded successfully
and now i want to download the same file but i am getting exception file not found.
The description given is like this -->
java.io.FileNotFoundException: .\temp\webdynpro\web\local\...\Components\com.sap.application\xyz.properties (The system cannot find the path specified)
xyz is the file uploaded on the server..
Please help.
Shilpa
Hi,
If you know that the file has been uploaded in c:/<folder name>/<file name>
Then give the same path to file download also.
Regards,
Vijai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hii Vijaya..
I have given the same path for the file download but the application is appending this path ":<b> .\temp\webdynpro\web\local\....\Components\com.sap.application\ " as default..
Now i dont understand why this path is getting appended with the path i specify..Thts why its not finding the file..Can u tell how to solve this..
Thanks
public void wdDoInit()
{
//@@begin wdDoInit()
IWDAttributeInfo attributeInfo =wdContext.getNodeInfo().getAttribute(IPrivateResultView.IContextElement.CTX__FILE_RESOURCE);
IWDModifiableBinaryType binaryType=(IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();
try {
String resourcePath = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),ResultView.FILE_NAME);
wdContext.currentContextElement().setCtx_FileResource(this.getByteArrayFromResourcePath(resourcePath));
binaryType.setFileName(ResultView.FILE_NAME);
binaryType.setMimeType(WDWebResourceType.JPG_IMAGE);
}
catch (WDAliasResolvingException e) {
wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), true);
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException("File not found on the server",true);
throw new WDRuntimeException(e);
}
//@@end
}
public void onActionDownload(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionDownload(ServerEvent)
try{
File output = new File("C:
xyz.properties");
int length =(int)output.length();
byte b[]= new byte[length];
FileInputStream in = new FileInputStream(output);
in.read(b);
in.close();
wdContext.currentContextElement().setCtx_FileResource(b);
}
catch(Exception ex)
{
wdComponentAPI.getMessageManager().reportSuccess("Error in File IO"+ex.toString());
}
IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("Ctx_FileResource");
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType)attinfo.getModifiableSimpleType();
//@@end
}
private static final String FILE_NAME = "xyz.properties";
Hi,
Use the code like this.
1) Create the button and bind the action for it.
2)then write this code in the action.
3) do not write any thing in the init method.
try {
final byte[] content = this.getByteArrayFromResourcePath("C:
xyz.properties");
final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.UNKNOWN);
try {
final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getAbsoluteURL(), "WD_Filedownload", false);
window.open();
}
catch(Exception e)
{
wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
}
5) writr the method getByteArrayFromResourcePath
//@@begin others
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();
}
//end
Regards,
Vijai
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.