+ Start a Discussion
KSusan CoxKSusan Cox 

File extention restrict in file tab

Hi,

       Is there any option to fetch file extention in ContentVersion SObject. I am trying to fetch the extention to block file.

      So any one know the solution. Please let me know ASAP.

Thanks.
Best Answer chosen by KSusan Cox
Vinit_KumarVinit_Kumar
You can query FileType on ContentVersion object something like below :-

ContentVersion cv = [SELECT FileType,id FROM ContentVersion limit 1];
system.debug('###########' + cv.FileType);

If this helps,please mark it as best answer to help others :)

All Answers

Vinit_KumarVinit_Kumar
You can query FileType on ContentVersion object something like below :-

ContentVersion cv = [SELECT FileType,id FROM ContentVersion limit 1];
system.debug('###########' + cv.FileType);

If this helps,please mark it as best answer to help others :)
This was selected as the best answer
KSusan CoxKSusan Cox
Hi Vinit,

Thanks for the suggestion. I tried it but it fatches only "TEXT" wether I upload txt file or doc file or any else.

 So, Please give me another solution.

Thanks.
Vinit_KumarVinit_Kumar
I ran the same query in my org and got the below results :-

FileType Id
1 TEXT 06890000001Ac2JAAS : This is for text file
2 PDF 06890000000hgLMAAY : This is for pdf file
3 WORD_X 06890000000gKcXAAU : This is for docs file.
KSusan CoxKSusan Cox
Hi Vinit,

     I also tried this but I got id "068E0000000YGkIIAW" for any file (e.g. Doc, xlsx, jpg, pdf).

     So, Please give me another solution.

Thanks.
Vinit_KumarVinit_Kumar
It seems you have only one file in your ContentVersion object.Can you try uploading few more different type files and run the query again.

If it's working for me,I don;t see any reason it should not work for you.