Its quite easy if you want to import data from excel to PS.
Create a derived Record having four(4) fields as shown in figure.
1. ATTACHADD (To add file from your PC to FTP from where your Server will get the file path)
2. ATTACHGET (To upload data from file)
3. ATTACHSYSFILENAME (To get the filename)
4. ATTACHUSEFILE(To get the user file name if needed)
Make a page containing theses fields.
Two buttons (Attachadd & Attachget)
Two fields to show the path (ATTACHSYSFILENAME & ATTACHUSERFILE)
Use the following code to attach file from your PC to FTP.
/*=============================================================*/
&RETCODE = AddAttachment(URL.IOBM_ATR_FTP, IOBM_FILE_ATTAC.ATTACHSYSFILENAME.Value | "DD_", "", IOBM_FILE_ATTAC.ATTACHUSERFILE, 0);
&MESSAGE_LVL = 1;
If (&RETCODE = %Attachment_Success) Then
IOBM_FILE_ATTAC.ATTACHUSERFILE.Value = "DD_" | IOBM_FILE_ATTAC.ATTACHUSERFILE;
/*** BSI,01-04-2011,ADDED CODE TO CHECK ATTACHED FILE EXTENSION, START ***/
End-If;
If IOBM_FILE_ATTAC.ATTACHUSERFILE.Value <> " " Then
&Within_string = IOBM_FILE_ATTAC.ATTACHUSERFILE.Value;
&Findcsv = Find(".csv", &Within_string);
&FindCapCSV = Find(".CSV", &Within_string);
If (&Findcsv = 0) And
&FindCapCSV = 0 Then
IOBM_FILE_ATTAC.ATTACHUSERFILE.Value = "";
Error "Only CSV File will be uploaded.";
End-If;
End-If;
/*=========================================================*/
Use the following code to upload data from file to PS.
/*=========================================================*/
Local File &MYFILE;
Local Record &REC;
Local array of string &ARRAY;
Local string &FilePath, &FileName;
Local Rowset &GRD_RS;
&REC = CreateRecord(Record.IOBM_ABC);
&FILE = IOBM_FILE_ATTAC.ATTACHUSERFILE.Value;
&URL = GetURL(URL.IOBM_ATR_GRID);
&MYFILE = GetFile(&URL | &FILE, "r", "a", %FilePath_Absolute);
If &MYFILE.IsOpen Then
While &MYFILE.ReadLine(&STRING);
&ARRAY = Split(&STRING, ",");
&REC.EMPLID.Value = &ARRAY [1];
&REC.IOBM_GPA.Value = &ARRAY [2];
&REC.Insert();
End-While;
End-If;