Options

Copy File by selection to specific folder

hhhhhhhqathhhhhhhqat Member Posts: 111
Hi ..


i create small form to collect some data for applicant , i add browse button to allow them for upload CV ... (not that meaning of upload )


i just want the applicant to browse the attached USB or any drive to select the CV document ( *.PDF or *.DOC) then the command will automatic make copy to specific folder ( C:\Applicant CV\ ) and give name of file by applicant NO+date+time.


can we do like that ????

thanks for every one helping me

Comments

  • Options
    geordiegeordie Member Posts: 655
    You can use OpenFile function of Common Dialog Management codeunit to let the user choose the file (take a look at report Import Budget from Excel for an example of usage) and File.COPY statement for copying, composing the target file name base on your requirement.
  • Options
    hhhhhhhqathhhhhhhqat Member Posts: 111
    i use this code



    FileName := CommonDialogMgt.OpenFile(Text006,'',2,'',0);
    FILE.COPY(FileName,'C:\cf\cv.pdf');

    it give error " file already exist"

    can you help me , i want every time different name based on selection and applicant No
  • Options
    geordiegeordie Member Posts: 655
    You need to "compose" the new file name and use it as second parameter of COPY function:
    NewFileName := 'C:\cf\cv_' + FORMAT(ApplicantNo) + '_' + FORMAT(CURRENTDATETIME,0,'<Year4><Month,2><Day,2>-<Hours24><Minute,2><Second,2>') + '.pdf';
    FILE.COPY(FileName,NewFileName);
    
  • Options
    hhhhhhhqathhhhhhhqat Member Posts: 111
    perfect geordie


    thanks for your usual help ...


    only one thing how can i make the output ( *.pdf and *.doc) .. now i can save and reopen (*.PDF) only , other files is not recognized.

    and also if the user select any files should not be accepted..


    thanks again for your help
  • Options
    geordiegeordie Member Posts: 655
    You can manage it retrieving the extension from the original file:
    NewFileName := 'C:\cf\cv_' + FORMAT(ApplicantNo) + '_' + FORMAT(CURRENTDATETIME,0,'<Year4><Month,2><Day,2>-<Hours24><Minute,2><Second,2>') + DELSTR(OldFileName,1,STRLEN(OldFileName)-4);
    

    Of course this works only with 3 characters extensions, should be better to extract from the original file name the part after the last dot and use it in order to manage extensions like ".xlsx".
  • Options
    hhhhhhhqathhhhhhhqat Member Posts: 111
    Hi geordie

    new code gives me below error..

    Microsoft Business Solutions-Navision
    The value of DELSTR parameter 3 is outside of the permitted range.

    The current value is: -4.
    The permitted range is: from 0 to 2147483647.

    OK
  • Options
    geordiegeordie Member Posts: 655
    hhhhhhhqat wrote:
    Hi geordie

    new code gives me below error..

    Microsoft Business Solutions-Navision
    The value of DELSTR parameter 3 is outside of the permitted range.

    The current value is: -4.
    The permitted range is: from 0 to 2147483647.

    OK

    Please check the file name chosen by user, in this case seems empty (length = 0).
  • Options
    hhhhhhhqathhhhhhhqat Member Posts: 111
    i double check the file name ,, it seems OK .. is there any issue related to Version ( currently i am using 4.0) ..
  • Options
    geordiegeordie Member Posts: 655
    hhhhhhhqat wrote:
    i double check the file name ,, it seems OK .. is there any issue related to Version ( currently i am using 4.0) ..

    No, it isn't related to the NAV version; you can add this check to control the error but I'm pretty sure it's related to a non-valid OldFileName value (how can you have a name, including the extension, shorter than 4 characters?):
    IF STRLEN(OldFileName) <= 4 THEN
      ERROR('File name not valid')
    ELSE
      NewFileName := 'C:\cf\cv_' + FORMAT(ApplicantNo) + '_' + FORMAT(CURRENTDATETIME,0,'<Year4><Month,2><Day,2>-<Hours24><Minute,2><Second,2>') + DELSTR(OldFileName,1,STRLEN(OldFileName)-4);
    
  • Options
    hhhhhhhqathhhhhhhqat Member Posts: 111
    i add the new code , it give me error " File name not valid "

    the old file is " d:\sam cv new.pdf"

    How can be the name include extension is less than 4.
Sign In or Register to comment.