Retrieve FileID from DotNetNuke using FileName

不羁岁月 提交于 2019-12-31 06:27:06

问题


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

回答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


来源:https://stackoverflow.com/questions/21905268/retrieve-fileid-from-dotnetnuke-using-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!