Question

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
Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top