GetFolderItem not working

  1. 2 weeks ago

    I have simple code, below

    IF RIGHT(ThisPathName, 1) <> "\" THEN
    ThisPathName = ThisPathName + "\"
    END IF
    
    ThisFilePath = ThisPathName + ThisFileName
    
    MsgBox (ThisFilePath)
    
    OpenFile = GetFolderItem(ThisFilePath, FolderItem.PathTypeAbsolute)
    
    
    IF OpenFIle <> Nil THEN
    Pic = Picture.Open(OpenFile)
    Pic = ResizeToFit(Pic,ImageWell1.WIdth, ImageWell1.Height)
    ImageWell1.Image = Pic
    ELSE
    MsgBox ("Bad File Name")
    END IF

    I have confirmed through MsgBox that the path and file name are correct, but the GetFolderItem returns Nil. The code trips the MsgBox at the end - Bad File Name. Nothing seems to work. Any help would be appreciated.

  2. Greg O

    Mar 10 Xojo Inc

    What is ThisPathName then this code is executed?

  3. Greg O

    Mar 10 Xojo Inc

    Since AbsolutePath is deprecated, you ought to be using NativePath or ShellPath anyway.

  4. Try

    OpenFile = GetFolderItem(ThisFilePath, FolderItem.PathTypeNative)

    plus

    Pic = Picture.Open(OpenFile,Folderitem.PathTypeNative)

  5. Jeff T

    Mar 11 Midlands of England, Europe
    GetFolderItem returns Nil

    Did you check that the ThisPathName refers to a real folder?
    Where do you get ThisPathName from?

    Try:

    dim parnt as folderitem = getfolderitem(ThisPathName)
    if parnt = nil then
    msgbox "Dont like that path!"
    else
    OpenFile = parnt.child(ThisFileName)
    if openfile <> nil and openfile.exists then
    Pic = Picture.Open(OpenFile)
    Pic = ResizeToFit(Pic,ImageWell1.WIdth, ImageWell1.Height)
    ImageWell1.Image = Pic
    else
    msgbox "Dont like the file!"
    end if
    end if

or Sign Up to reply!