IWebFileDialog.Execute

Syntax

Execute: Boolean;

Description

The Execute method initializes the dialog box and returns the user selection result.

Comments

The method returns True if the Open/Save button was pressed in the dialog box, otherwise, it returns False.

When working with the FileOpenDialog dialog box, and if the Open button was pressed, path and name of the selected file will be available in the FileName property. File contents will be available in the FileData thread.

If the  dialog box is initialized, before calling the Execute method one should determine the FileData property.

Example

Executing the example requires that the repository contains a folder with the F_DOCUMENT identifier and a document with the D_IMAGE identifier. There should also be a web form with two buttons, the FileOpenDialog and FileSaveDialog components. The OnClick event handlers are created for the buttons. Web form code is displayed below.

Add a link to the IO system assembly.

Class TESTWebForm: WebForm
    FileOpenDialog1: WebFileOpenDialog;
    FileSaveDialog1: WebFileSaveDialog;
    OpenBtn: WebButton;
    SaveBtn: WebButton;

    Sub OpenBtnOnClick;
    Var
        Mb: IMetabase;
        CrInfo: IMetabaseObjectCreateInfo;
        MObj: IMetabaseObject;
        Doc: IDocument;
    Begin
        FileOpenDialog1.Filter := ".txt";
        If FileOpenDialog1.Execute Then
            Mb := MetabaseClass.Active;
            CrInfo := Mb.CreateCreateInfo;
            CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_DOCUMENT;
            CrInfo.Id := Mb.GenerateId("DOC_TXT");
            CrInfo.Name := Path.GetFileName(FileOpenDialog1.FileName);
            CrInfo.Parent := MB.ItemById("F_DOCUMENT");
            // Create a new document in the repository and load the selected file to it
            MObj := MB.CreateObject(CrInfo).Edit;
            Doc := MObj As IDocument;
            Doc.LoadFromStream(FileOpenDialog1.FileData);
            Doc.FileName := CrInfo.Name;
            MObj.Save;
        End If;
    End Sub OpenBtnOnClick;

    Sub SaveBtnOnClick;
    Var
        Mb: IMetabase;
        Doc: IDocument;
    Begin
        Mb := MetabaseClass.Active;
        Doc := Mb.ItemById("D_IMAGE").Bind As IDocument;
        // Set up and initialize save dialog box
        FileSaveDialog1.FileData := Doc.GetAsStream;
        FileSaveDialog1.FileName := Doc.FileName;
        If FileSaveDialog1.Execute Then
            Self.Text := "Document is saved in the file system.";
        End If;
    End Sub SaveBtnOnClick;
End Class TESTWebForm;

Clicking the OpenBtn button initializes the file opening dialog box. One can select only text files in the dialog box. If one selects the file and clicks the Open button, a new document is created based on the selected file is created in the repository.

Clicking the SaveBtn button initializes the file saving dialog box. The file contained in the D_IMAGE document is used as a file to be saved. Clicking the Save button saved the file in the file system using browser tools.

See also:

IWebFileDialog