on 06-20-2007 8:35 PM
Hello, I am using the file upload UI element for uploading a local file and processing it. However, I do not know how to validate a manual input (if the user just types in something as the filename). Any processing after putting in a non-existing file (or nonsense) seems to hang forever. Could anyone propose a check for file existence in this case? Best regards, Werner
I paste the code which hangs if the file does not exist:
Code:
//create a ressource from the file data given
IWDResource myresource;
myresource = WDResourceFactory.createResource(wdContext.currentContextElement().getFileData().read(true),
wdContext.currentContextElement().getFileData().getResourceName(), WDWebResourceType.DOC, true);
Welcome to SDN..
Here is the sample code:
String fileType = fileResource.getResourceType().getFileExtension().toUpperCase();
if ("PDF".equals(fileType) || "DOC".equals(fileType) || "RTF".equals(fileType) || "TXT".equals(fileType))
{
// Your Logic
}
<i>*Reward each useful answer</i>
Raja T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi sumit
Can u provide little detail abt the solution u provided. I used file exists code but its not workin i have pasted the code I have used:
String hostName = TaskBinder.getCurrentTask().getProtocolAdapter().getServerName();
int port = TaskBinder.getCurrentTask().getProtocolAdapter().getServerPort();
String Protocol =TaskBinder.getCurrentTask().getProtocolAdapter().getProtocolScheme();
String logoName = "logo_" + wdContext.currentCompaniesElement().getBukrs()+".gif";
String companylogourl = Protocol + "://" + hostName + ":" + port + "/webdynpro/resources/local/eScCommonLogos/Components/com.ko.CommonLogos/" + logoName;
/Checking availablility of the image/
//String fileName=companylogourl;
File f=new File(companylogourl);
if (f.exists())
{
wdComponentAPI.getMessageManager().reportSuccess("file found");
wdContext.currentContextElement().setCxt_CompanyLogo(companylogourl);
}
else
{
wdComponentAPI.getMessageManager().reportSuccess("file Not found");
Please help if possible...
Thanks & Regards
Jaspreet Kaur
Hi Werner,
Try the folowing code:
IWDClientUser objUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser objSAPUser = objUser.getSAPUser();
IUser ep5User = WPUMFactory.getUserFactory().getEP5User(objSAPUser);
String strLocation = "<specify the path>";
RID objNewRid = RID.getRID(strLocation);
objResourceContext = new ResourceContext(ep5User);
objFactory = ResourceFactory.getInstance();
objResourceCheckRowwiseFolder = objFactory.getResource(objNewRid,objResourceContext);
if(objResourceCheckRowwiseFolder==null) //This checks whether such a folder exists or not.
{
}
else
{
}
Regards,
Shyam.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi werner,
Do the following steps
In wdDoInit, create an element(instance) of the node. For this, declare the instance globally since it will be used in more than one methods (wdDoInit, onActionFileToSever).
It is declared as:
IPrivateFileUploadView.IFileElement element; (in begin others)
(FileUploadView is the name of the view)
In the onActionFileToServer method, specify the location where you want the file to be uploaded. On browsing, you get the file name in the value attribute assigned to the filename property of FileUpload (File.FileName, in this case). Create a file by this name in the sever. The contents of the file is present in the value attribute Upload in the form of binary data. This is written to the file created. This happens when you click the FileToServer button. The code for this is given below.
N.B.:- Settings needed to be made in server for uploading a file.
In VisualAdminServicesWeb Container, set the parameter MultipartBodyParameterName to com.sap.servlet.multipart.body
Thanks,
P.Manivannan.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.