Retrieve FileID from DotNetNuke using FileName

I’m trying to get the FileID of a file based on the FileName. This is what I have, but it returns false. Any ideas?

  Dim oFileInfo As New DotNetNuke.Services.FileSystem.FileInfo
    oFileInfo.FileName = "4secapplication.PNG"

    Dim FileID As Integer

    Dim oFolderInfo As New DotNetNuke.Services.FileSystem.FolderInfo
    oFolderInfo.FolderPath = "uploads/files/"

    If FileManager.Instance.FileExists(oFolderInfo, "4secapplication.PNG") = True Then

        FileID = oFileInfo.FileId
    Else
        lblExceptions.Text = "not exists"
    End If

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I suggest you something like that:

    Dim oFileInfo As New DotNetNuke.Services.FileSystem.FileInfo

    Dim FileID As Integer

    Dim oFolderInfo As New DotNetNuke.Services.FileSystem.FolderInfo
    If FolderManager.Instance.FolderExists(PortalId, "uploads/files/") Then
        oFolderInfo = FolderManager.Instance.GetFolder(PortalId, "uploads/files/")
        If FileManager.Instance.FileExists(oFolderInfo, "4secapplication.PNG") = True Then
            oFileInfo = FileManager.Instance.GetFile(oFolderInfo, "4secapplication.PNG")
            FileID = oFileInfo.FileId
        Else
            lblExceptions.Text = "not exists"
        End If

    End If

Or a shortest method:

    Dim oFileInfo As DotNetNuke.Services.FileSystem.FileInfo = FileManager.Instance.GetFile(PortalId, "uploads/files/4secapplication.PNG")

    Dim FileID As Integer

    If oFileInfo IsNot Nothing Then
        FileID = oFileInfo.FileId
    Else
        lblExceptions.Text = "not exists"
    End If


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x