此代码在开发中使用 IIS 7.5 打印文件的扩展属性,但在运行 IIS 8 的生产服务器上运行时找不到属性。
没有错误,并且属性确实出现在 Windows 资源管理器中。
Protected files as String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadDim videoPath As String = Server.MapPath("library/video/")
Dim videoPath As String = Server.MapPath("library/video/")
Dim videoFolder As New DirectoryInfo(videoPath)
Dim attrib As String
Dim titleDisplay As String
For Each fil As FileInfo In videoFolder.GetFiles("*.mp4")
titleDisplay = fil.Name().Replace(fil.Extension(), "")
attrib = getAttribute(fil, "Title")
If attrib.Length > 0 Then
titleDisplay &= "<br /><b>" & attrib & "</b>"
End If
attrib = getAttribute(fil, "Tags")
For Each att In attrib.Split(";")
titleDisplay &= "<br /><i>" & att & "</i>"
Next
files &= "<p>" & titleDisplay & "</p>"
Next
End Sub
Private Function getAttribute(ByVal file As FileInfo, ByVal attribute As String) As String
Dim value As String = ""
Dim shell As New Shell32.Shell()
Dim fld As Shell32.Folder = shell.NameSpace(Path.GetDirectoryName(file.FullName))
For Each s In fld.Items()
If fld.GetDetailsOf(s, 0).ToLower() = Path.GetFileName(file.FullName).ToLowerInvariant Then
For i As Integer = 0 To 34
If fld.GetDetailsOf(fld.Items, i) = attribute Then
value = fld.GetDetailsOf(s, i)
Exit For
End If
Next
Exit For
End If
Next
Return value
End Function