on 07-12-2007 7:57 AM
Hi All,
I am trying to upload a file using the File Upload Control. I have already bound the data and resource property with the context attributes. Can someone please suggest that what can be done to validate the file path? For eg. if i enter "abcd" in the file path and click a button for uploading the file. My application simply "<b>HANGS UP</b>" without even reaching the code what i have written on action of the button.
Is there any way to permit the user to enter the path only through Browse button and not manually? Please reply ASAP.
Thanks and Regards,
Smriti
Hi Smriti
Use this code in action button for upload a file
InputStream text = null;
int temp = 0;
try
{
File file = new File(wdContext.currentContextElement().getUp().getResourceName());
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getUp()!=null)
{
text = wdContext.currentContextElement().getUp().read(false);
while((temp=text.read())!=-1)
{
op.write(temp);
}
}
op.flush();
op.close();
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
}
catch(Exception e)
{
e.printStackTrace();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Smiriti,
up is a context attribute of type "com.sap.ide.webdynpro.uielementdefinitions.Resource"
It is to be bind with upload UI element property called "resource"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sathish,
If i write this line:
File file = new File(wdContext.currentContextElement().getResource());
where "Resource" is the context attribute to which i have bound the "Resource" property of File Upload control
it gives me an error:
"The constrcutor File(IWDResource) is undefined"
Regards,
Smriti
Hi Smriti,
For the context attribute Resource you set the property "type" as "com.sap.ide.webdynpro.uielementdefinitions.Resource"
Then u bind that attribute to Upload UI element property "resource".After that u write this code
File file = new File(wdContext.currentContextElement().getResource().getResourceName());
Hi Sathish,
I tried to paste this code in the Action method of the Upload button but the application still hangs. I tried to debug, but the sad part is that control never goes this method. The application keeps on being in wait state even if i terminate the thread from debug mode.
Regards,
Smriti.
Hi Sathish,
I want that even if customer enters file path as "abcdefg", an error should be thrown. Is there any way to do so? I am unable to catch this exception beacuse when a path something like "andbevd" is entered, the application simply hangs up irrespective of whatever code i write in the "Upload Button"'s action method.
Please suggest if there is some way to restrict the user from entering in the input field directly, I mean he should be able to enter the path only by choosing from the "Browse" button.
Thanks and Regards,
Smriti
Hi Smriti,
The definition of File Up load UI element is given below
You can use the FileUpload UI element to upload files from the client to the server. The UI element appears with <b>an input field, in which the directory path and the file name appear, and a button</b> for searching for the file.
From this i think we must give the directory name.
Hi Smriti,
why don't u validate with the resourcename (i.e., your directory path)... get the resourcename in a string and check with the string is there any characters with (: or / etc... as it is mandatory for any directory path and then finally upload the file...
if the user enters "abc" over the input field in FileUpload UI, it will throw an error as u can catch it and throw ur message. Or else u can specify a default path which can be binded with the resource path during the execution...
Regards / Guru
Hi Smriti,
Have a look on the Following Links... which clearly briefs what is the use of FileUpload UI and how it works behind the screen...
<a href="/people/dagfinn.parnas/blog/2004/08/15/inputfile-how-to-hide-the-plain-browse-button you about the how the FileUplaod UI is being built.</a>
<a href="/people/dagfinn.parnas/blog/2004/08/15/inputfile-how-to-hide-the-plain-browse-button more stuff on FileUpload UI</a>
<a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;892442">How the FileUpload UI interacts with the local system</a>
After going thru above post, you can identify that the inputField is being declared as FILE type (like <input type="file" >), and you would also noticed the cause for your error in the last link which I have specified above, and what microsoft also recommends for it as a solution to show an alternative message in place of the blank screen...
Hope now you would be clear...why your method is not being invoked..
Please revert back for futher queries... try to come soon with an alernative solution...
Regards / Guru
Message was edited by:
Armin Reichert
Hi Smriti,
Well, you have one more option where u can first acknowledge the User whenever he opens the View.
For Eg, When the user navigates to the FileUpload View, We make focus on the InputField of the FileUploadUI and pass a message to the User, saying that"Specify the complete path if it thru manual process..." or something else...
To do that,
Navigate to wddomodifyview(), and paste the following code...
IWDFileUpload messagespot=(IWDFileUpload)view.getElement("FileUpload");
messagespot.requestFocus();
Thus, the inputField will be highlighted with a user message either from Message Pool or normal messages like...
wdComponentAPI.getMessagemanager.reportSuccess("Please enter the complete path of thee file if it is manual process...") in the wdDoinit() method...
by this way we acknowledge the user... will try is there could be any other solution...
Regards / Guru
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.