使用FileName从DotNetNuke中检索FileID

时间:2014-02-20 10:41:47

标签: asp.net dotnetnuke dotnetnuke-7

我正在尝试根据FileName获取文件的FileID。这就是我所拥有的,但它返回false。有什么想法吗?

  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

1 个答案:

答案 0 :(得分:2)

我建议你这样:

    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

或最简短的方法:

    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