Aber sowas von und ist kaum aufwendiger als die MF-Variante.DTF schrieb:
Also via IPropertyStore geht es doch
WinRT-Variante (war nur ein Testprojekt, daher ist da ein bissel mehr drin, mit Verweis auf die Windows.winmd, zusätzlich das Nuget-Paket: System.Runtime.WindowsRuntime.dll, kann man natürlich auch ohne Verweis und NuGet ausschließlich mit WinRT COM-Interfaces und APIs machen)
VB.NET-Quellcode
-
- Imports Windows.Storage
- Imports Windows.Storage.FileProperties
- Public Class Form1
- Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim FOP As New Pickers.FileOpenPicker With {
- .SuggestedStartLocation = Pickers.PickerLocationId.ComputerFolder,
- .ViewMode = Pickers.PickerViewMode.List
- }
- Dim FTF As IList(Of String) = FOP.FileTypeFilter
- FTF.Add("*")
- If FOP.InitializeWithWindow(Me) Then
- Dim StorFile As StorageFile = Await FOP.PickSingleFileAsync
- If StorFile IsNot Nothing Then
- GetFileProperties(StorFile.Path)
- End If
- End If
- End Sub
- Private Async Sub GetFileProperties(File As String)
- Dim StorFile As StorageFile = Await StorageFile.GetFileFromPathAsync(File)
- If StorFile IsNot Nothing Then
- Dim FileProperties As IDictionary(Of String, Object) = Await StorFile.Properties.RetrievePropertiesAsync(Nothing)
- If FileProperties IsNot Nothing Then
- Debug.Print("PropertyCount: " & FileProperties.Count.ToString)
- If FileProperties.Count > 0 Then
- Try
- For Each ValuePair As KeyValuePair(Of String, Object) In FileProperties
- Debug.Print(ValuePair.Key & ": " & GetValuePairValueAsString(ValuePair))
- Next
- Catch ex As Exception
- ' do nothing
- End Try
- End If
- End If
- Dim ExtraProperties As New List(Of String)
- 'ExtraProperties.Add("{b725f130-47ef-101a-a5f1-02608c9eebac} 18")
- ExtraProperties.Add("System.FileAllocationSize")
- Dim ExtraFileProperties As IDictionary(Of String, Object) = Await StorFile.Properties.RetrievePropertiesAsync(ExtraProperties)
- If ExtraFileProperties IsNot Nothing Then
- If ExtraFileProperties.Count > 0 Then
- Try
- For Each ValuePair As KeyValuePair(Of String, Object) In ExtraFileProperties
- Debug.Print(ValuePair.Key & ": " & GetValuePairValueAsString(ValuePair))
- Next
- Catch ex As Exception
- ' do nothing
- End Try
- End If
- End If
- Debug.Print("Name: " & StorFile.Name)
- Debug.Print("Path: " & StorFile.Path)
- Debug.Print("DateCreated: " & StorFile.DateCreated.DateTime.ToString)
- Debug.Print("ContentType: " & StorFile.ContentType)
- Debug.Print("DisplayName: " & StorFile.DisplayName)
- Debug.Print("DisplayType: " & StorFile.DisplayType)
- Debug.Print("FileType: " & StorFile.FileType)
- Debug.Print("FolderRelativeId: " & StorFile.FolderRelativeId)
- Debug.Print("Attributes: " & StorFile.Attributes.ToString)
- Debug.Print("ProviderId: " & StorFile.Provider.Id)
- Debug.Print("ProviderDisplayName: " & StorFile.Provider.DisplayName)
- Dim StdProperties As BasicProperties = Await StorFile.GetBasicPropertiesAsync
- If StdProperties IsNot Nothing Then
- Debug.Print("ItemDate: " & StdProperties.ItemDate.DateTime.ToString)
- Debug.Print("DateModified: " & StdProperties.DateModified.DateTime.ToString)
- Debug.Print("Size: " & StdProperties.Size.ToString)
- End If
- Dim ContentType As String = StorFile.ContentType
- If ContentType.Contains("image") Then
- Dim ImgProperties As ImageProperties = Await StorFile.Properties.GetImagePropertiesAsync
- If ImgProperties IsNot Nothing Then
- Debug.Print("Orientation: " & ImgProperties.Orientation.ToString)
- Debug.Print("CameraManufacturer: " & ImgProperties.CameraManufacturer)
- Debug.Print("CameraModel: " & ImgProperties.CameraModel)
- Debug.Print("Width: " & ImgProperties.Width.ToString)
- Debug.Print("Height: " & ImgProperties.Height.ToString)
- Debug.Print("Longitude: " & ImgProperties.Longitude.ToString)
- Debug.Print("Latitude: " & ImgProperties.Latitude.ToString)
- Debug.Print("Rating: " & ImgProperties.Rating.ToString)
- Debug.Print("DateTaken: " & ImgProperties.DateTaken.DateTime.ToString)
- Debug.Print("Title: " & ImgProperties.Title)
- Debug.Print("Keywords: " & String.Join(",", ImgProperties.Keywords))
- Debug.Print("PeopleNames: " & String.Join(",", ImgProperties.PeopleNames))
- End If
- ElseIf ContentType.Contains("audio") Then
- Dim MusProperties As MusicProperties = Await StorFile.Properties.GetMusicPropertiesAsync
- If MusProperties IsNot Nothing Then
- Debug.Print("Artist: " & MusProperties.Artist)
- Debug.Print("Album: " & MusProperties.Album)
- Debug.Print("Subtitle: " & MusProperties.Subtitle)
- Debug.Print("Writers: " & String.Join(",", MusProperties.Writers))
- Debug.Print("Producers: " & String.Join(",", MusProperties.Producers))
- Debug.Print("AlbumArtist: " & MusProperties.AlbumArtist)
- Debug.Print("Bitrate: " & MusProperties.Bitrate.ToString)
- Debug.Print("Composers: " & String.Join(",", MusProperties.Composers))
- Debug.Print("Conductors: " & String.Join(",", MusProperties.Conductors))
- Debug.Print("Duration: " & MusProperties.Duration.ToString)
- Debug.Print("Genre: " & String.Join(",", MusProperties.Genre))
- Debug.Print("Publisher: " & MusProperties.Publisher)
- Debug.Print("Rating: " & MusProperties.Rating.ToString)
- Debug.Print("Subtitle: " & MusProperties.Subtitle)
- Debug.Print("Title: " & MusProperties.Title)
- Debug.Print("TrackNumber: " & MusProperties.TrackNumber.ToString)
- Debug.Print("Year: " & MusProperties.Year.ToString)
- End If
- ElseIf ContentType.Contains("video") Then
- Dim VidProperties As VideoProperties = Await StorFile.Properties.GetVideoPropertiesAsync
- If VidProperties IsNot Nothing Then
- Debug.Print("Subtitle: " & VidProperties.Subtitle)
- Debug.Print("Writers: " & String.Join(",", VidProperties.Writers))
- Debug.Print("Latitude: " & VidProperties.Latitude.ToString)
- Debug.Print("Longitude: " & VidProperties.Longitude.ToString)
- Debug.Print("Producers: " & String.Join(",", VidProperties.Producers))
- Debug.Print("Orientation: " & VidProperties.Orientation.ToString)
- Debug.Print("Bitrate: " & VidProperties.Bitrate.ToString)
- Debug.Print("Directors: " & String.Join(",", VidProperties.Directors))
- Debug.Print("Duration: " & VidProperties.Duration.ToString)
- Debug.Print("Height: " & VidProperties.Height.ToString)
- Debug.Print("Width: " & VidProperties.Width.ToString)
- Debug.Print("Orientation: " & VidProperties.Orientation.ToString)
- Debug.Print("Publisher: " & VidProperties.Publisher)
- Debug.Print("Rating: " & VidProperties.Rating.ToString)
- Debug.Print("Title: " & VidProperties.Title)
- Debug.Print("Year: " & VidProperties.Year.ToString)
- End If
- Else
- Dim DocProperties As DocumentProperties = Await StorFile.Properties.GetDocumentPropertiesAsync
- If DocProperties IsNot Nothing Then
- Debug.Print("Author: " & String.Join(",", DocProperties.Author))
- Debug.Print("Keywords: " & String.Join(",", DocProperties.Keywords))
- Debug.Print("Comment: " & DocProperties.Comment)
- Debug.Print("Title: " & DocProperties.Title)
- End If
- End If
- End If
- End Sub
- Private Function GetValuePairValueAsString(ValuePair As KeyValuePair(Of String, Object)) As String
- Dim strRet As String = String.Empty
- If ValuePair.Value IsNot Nothing Then
- Select Case ValuePair.Value.GetType
- Case GetType(String)
- strRet = CType(ValuePair.Value, String)
- Case GetType(String())
- strRet = String.Join(",", CType(ValuePair.Value, String()))
- Case GetType(Boolean)
- strRet = CType(ValuePair.Value, Boolean).ToString
- Case GetType(Short)
- strRet = CType(ValuePair.Value, Short).ToString
- Case GetType(UShort)
- strRet = CType(ValuePair.Value, UShort).ToString
- Case GetType(Integer)
- strRet = CType(ValuePair.Value, Integer).ToString
- Case GetType(UInteger)
- strRet = CType(ValuePair.Value, UInteger).ToString
- Case GetType(Long)
- strRet = CType(ValuePair.Value, Long).ToString
- Case GetType(ULong)
- strRet = CType(ValuePair.Value, ULong).ToString
- Case GetType(Single)
- strRet = CType(ValuePair.Value, Single).ToString
- Case GetType(Double)
- strRet = CType(ValuePair.Value, Double).ToString
- Case GetType(DateTimeOffset)
- strRet = CType(ValuePair.Value, DateTimeOffset).DateTime.ToString
- Case GetType(Guid)
- strRet = CType(ValuePair.Value, Guid).ToString
- Case GetType(Object())
- For Each Obj In CType(ValuePair.Value, Object())
- Select Case Obj.GetType
- Case GetType(String)
- strRet = CType(Obj, String)
- Case GetType(String())
- strRet = String.Join(",", CType(Obj, String()))
- Case GetType(Boolean)
- strRet = CType(Obj, Boolean).ToString
- Case GetType(Short)
- strRet = CType(Obj, Short).ToString
- Case GetType(UShort)
- strRet = CType(Obj, UShort).ToString
- Case GetType(Integer)
- strRet = CType(Obj, Integer).ToString
- Case GetType(UInteger)
- strRet = CType(Obj, UInteger).ToString
- Case GetType(Long)
- strRet = CType(Obj, Long).ToString
- Case GetType(ULong)
- strRet = CType(Obj, ULong).ToString
- Case GetType(Single)
- strRet = CType(Obj, Single).ToString
- Case GetType(Double)
- strRet = CType(Obj, Double).ToString
- Case GetType(DateTimeOffset)
- strRet = CType(Obj, DateTimeOffset).DateTime.ToString
- Case GetType(Guid)
- strRet = CType(Obj, Guid).ToString
- Case Else
- strRet = "Unknown ObjectArrayType: " & Obj.GetType.ToString
- End Select
- Next
- Case Else
- strRet = "Unknown ValuePairType: " & ValuePair.Value.GetType.ToString
- End Select
- End If
- Return strRet
- End Function
- End Class
Das reicht für diese Jahr.
Mfg -Franky-