You need to sign in to do that
Don't have an account?
salesforce@14
How to check the file type is csv or not using apex.
Hi,
I have to check the file is csv or not while uploading it, if not then i want to display the error message, otherwise it gets upload without showing the error "Error:BLOB is not a valid UTF-8 string"
Thanks in Advance
I have to check the file is csv or not while uploading it, if not then i want to display the error message, otherwise it gets upload without showing the error "Error:BLOB is not a valid UTF-8 string"
Thanks in Advance
Atlast i found the solution.
I replaced that exception with custom label in catch block like below
if(errorMessage.contains('BLOB is not a valid UTF-8 string'))
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR,system.label.Please_Select_Valid_CSV_File));
}
Thanks.
All Answers
Try using TRY CATCH method,
Hope this might help you.
Thanks
If your file is saved as CSV then it will not show this error "BLOB is not a validaUTF_8 string" so , you can check the blob type if while converting it to string if you will get this error like "BLOB is not a valid UTF-8 string" means file which you are trying to fetch is not saved as CSV . and based on that you can display the message.
Thanks,
Keyur Modi
If you don't want to use apex coding for checking file type then you have to use java script for checking the file type.
you should refer this link got this
http://stackoverflow.com/questions/7977084/check-file-type-when-form-submit
If this will help you then please select as beat answer.
Thanks
Thanks for your reply.
why we cannot check the file in if condition using apex?
Is there any way like this to do.
Thanks.
I fyou want to show the error mesage use Saran's code and along with that you need to add <apex:PageMessages /> into the <apex:form></apex:form> tag u you have used.
Thanks :)
I want to show the error message only for the other files not for the csv file. So how to find out the file is not csv and display the error message in page.
Thanks.
I am using <apex:PageMessages /> tag inside the form only.
Thanks.
Copy paste that TRY CATCH method in the controller.
Thanks,
Please explain me briefly..
Thanks.
So usually we will convert the body of the documnt to string and then continue with our process.
So i am taking the body of the document which i am attaching as doc.body which is a blob type.
It will be more helpful to identiy the error if you post your code
Thanks
public string nameFile{get;set;}
public Blob contentFile{get;set;}
nameFile=contentFile.toString();
I did upto this and after that how to check the nameFile is csv or not.
Thanks
Hope this helps.
Thanks!
Thanks for your reply.
But actually i did like above only.
Atlast i found the solution.
I replaced that exception with custom label in catch block like below
if(errorMessage.contains('BLOB is not a valid UTF-8 string'))
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR,system.label.Please_Select_Valid_CSV_File));
}
Thanks.