码迷,mamicode.com
首页 > 其他好文 > 详细

Dynamic 365中读取CSV文件

时间:2018-07-08 19:08:48      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:style   family   rtp   mat   bottom   public   ext   读取文件   add   

 

 

 

Dynamic 365开发中对于读取CSV文件与2012略有不同。Dynamic 365中,对于文件的处理是先上传,后下载的过程。需要通过FileUpload control Upload strategy class FileUploadTemporaryStorageStrategy类来实现对于文件的读取和下载。

以下是一个简单的例子可供参考:

Dilaog窗体,读取文件上传到本地服务器中,以URL方式可以查看

 

 Public Object dialog()
    {
        DialogGroup      dialogGroup;
        FormBuildControl formBuildControl;
        FileUploadBuild  dialogFileUpload;
        #file
        ;
       
        dialog = super();
        dialogGroup = dialog.addGroup("File path");
        formBuildControl = dialog.formBuildDesign().control(dialogGroup.name());
        dialogFileUpload = formBuildControl.addControlEx(classstr(FileUpload), "dialogFileUpload");
        dialogFileUpload.style(FileUploadStyle::MinimalWithFilename);
        dialogFileUpload.baseFileUploadStrategyClassName(classstr(FileUploadTemporaryStorageStrategy));
        dialogFileUpload.fileTypesAccepted(".csv");
        dialogFileUpload.fileNameLabel("Select a file to upload");
       
        return dialog;
    }

 

得到控件名:

   protected FormControl getFormControl(DialogRunbase _dialog, str _controlName)
     {
          return _dialog.formRun().control(_dialog.formRun().controlId( _controlName));
     }

获取文件:

public boolean getFromDialog(  
    {
        boolean ret;
        ;
        ret = super();
        FileUpload     fileupload;
        fileupload  =   this.getFormControl(dialog, "dialogFileUpload");

        fileName      = fileupload.fileName();
        if (fileName == ‘‘)
        {
            checkFailed("File name empty");
        }

        return ret;
    }

读取数据:

 private void readData()
    {

  int                               startpos;
        int                              fieldCSVPos;
        container                   conData ;
        SysDictTable             sysDictTable;
        container                   currentLine;
        int                              totalOfLines;

        CommaTextStreamIo           localStream;


        FileUpload fileUploadControl = this.getFormControl(dialog,  “dialogFileUpload”);
       
        FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();
       
        if (fileUploadResult != null && fileUploadResult.getUploadStatus())
        {
            fileName = fileUploadResult.getDownloadUrl();
        }
       
        localStream = CommaTextStreamIo::constructForRead(File::UseFileFromURL(fileName));
      
         
        if (localStream.status() != IO_Status::Ok)
        {
            throw error(strfmt(‘Is not possible to open the file. Error %1‘,enum2str(localStream.status())));
        }


        localStream.inFieldDelimiter("\,");
        localStream.inRecordDelimiter("\n");
   
        currentLine = localStream.read();

  startpos = 1;//定义读取数据的开始行标

        ttsbegin;
      
        while (currentLine)
        {

            if ( currentLine == connull() ) continue ;

            row++ ;

            if ( row  < startpos ) continue ;

           this.writeData(currentLine) ;
           //  info(strFmt(‘%1‘,conPeek(currentLine,2)));

            currentLine = localStream.read();
        }
        ttscommit;

    }

  欢迎大家讨论,一起学习。

想了解更多,可参考 https://community.dynamics.com/ax/b/365operationswithsukrut/archive/2017/09/28/d365fo-use-of-fileupload-control-to-read-csv-file

 

Dynamic 365中读取CSV文件

标签:style   family   rtp   mat   bottom   public   ext   读取文件   add   

原文地址:https://www.cnblogs.com/sunny-technology/p/9280737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!