cancel
Showing results for 
Search instead for 
Did you mean: 

Excel File Upload Validation

Former Member
0 Kudos

Hi Friends,

I have one doubt on File Upload functionality. All ready I have done that file upload code but here I am looking one problem. My Req is I have to upload only the u201CHX10STCKBL.xlsu201D if client will change the file name the excel file is not upload.

Means I need Validation if client upload u201CHX10STCKBL.xlsu201D it is upload or can change Excel File name that time it is not uploaded.

I have to done this code for File upload.

InputStream text = null;

int temp = 0;

try

{

File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());

wdComponentAPI.getMessageManager().reportSuccess("filePath Vijay123:::"+file);

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();

path = file.getAbsolutePath();

wdComponentAPI.getMessageManager().reportSuccess(path);

}

}

catch(Exception ex)

{

ex.printStackTrace();

}

Here file will saved Server Path.

Regards

Vijay Kalluri

Accepted Solutions (1)

Accepted Solutions (1)

p330068
Active Contributor
0 Kudos

Hi Vijay,

Please try to get the name of the excel file like .

String strFilename = wdContext.currentContextElement().getResource().getResourceName().toString();

if (strFilename != null && strFilename.equalsIgnoreCase("HX10STCKBL.xls"))

{

//Procees for upload code

{

else

{

// Put the message here if file is not correct

}

Hope it helps

Regards

Arun

Answers (1)

Answers (1)

former_member214651
Active Contributor
0 Kudos

Hi,

What u can do is get the name of the file when he clicks on the upload button. If the name is changed or does not match the required format then you can throw an error using the message manager API.

if(!("HX10STCKBL").equals(wdContext.currentContextElement().getResource().getResourceName().toString()))
{
   wdComponentAPI().getMessageManager().reportException("File name not Valid");
}

Hope this helps you.

Regards,

Poojith MV