locked
SOAP Serialization -{"Token StartElement in state Epilog would result in an invalid XML document."} RRS feed

  • Question

  • System.InvalidOperationException was unhandled
      HResult=-2146233079
      Message=There was an error generating the XML document.
      Source=System.Xml
      StackTrace:
           at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
           at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
           at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
           at WindowsApplication1.Form1.SavePlayList(String Filename) in C:\Users\RocketShip\Desktop\F Drive - My Files\Organized Files\Projects\vidplayerExample\vidplayerExample\Form1.vb:line 403
           at WindowsApplication1.Form1.ToCRDelimitedTextFileToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\RocketShip\Desktop\F Drive - My Files\Organized Files\Projects\vidplayerExample\vidplayerExample\Form1.vb:line 739
           at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
           at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
           at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
           at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
           at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ToolStrip.WndProc(Message& m)
           at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.InvalidOperationException
           HResult=-2146233079
           Message=Token StartElement in state Epilog would result in an invalid XML document.
           Source=System.Xml
           StackTrace:
                at System.Xml.XmlTextWriter.AutoComplete(Token token)
                at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)
                at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns)
                at System.Xml.Serialization.XmlSerializationWriter.WriteArray(String name, String ns, Object o, Type type)
                at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElement(String name, String ns, Object o, Type ambientType)
                at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElements()
                at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_AvbMediaPlayerPlaylist(Object o)
           InnerException: 

    Any ideas?

    I have made this serialization sub:

        Sub SavePlayList(ByVal Filename As String)
            Dim PlaylistItems As New List(Of MyVideo)
            For Each Item In ListBox1.Items
                Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
                PlaylistItems.Add(MediaItem)
            Next
            Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
            Dim SoapMapping As Xml.Serialization.XmlTypeMapping = _
                (New Xml.Serialization.SoapReflectionImporter).ImportTypeMapping(GetType(AvbMediaPlayerPlaylist))
            Dim Serializer As New Xml.Serialization.XmlSerializer(SoapMapping)
            Using sw As New StreamWriter(Filename)
                Serializer.Serialize(sw, PlayList)
            End Using
        End Sub

    With this class to hold the playlist for serialization

    <Serializable()>
    Public Class AvbMediaPlayerPlaylist
        Public PlaylistMediaItems As List(Of MyVideo)
        Sub New(ByVal PlayListItems As List(Of MyVideo))
            Me.PlaylistMediaItems = PlayListItems
        End Sub
        Sub New()
    
        End Sub
    End Class

    And that class is a list of this object:

    Option Strict On
    <Serializable()>
    Public Class MyVideo
        Private _fileName As String
        Private Property _listBoxText As String
        Public Property IsYoutubeObject As Boolean = False
        Public Property ListBoxText As String
            Get
                Return _listBoxText
            End Get
            Set(ByVal value As String)
                _listBoxText = value
            End Set
        End Property
        Public Property Filename As String
            Get
                Return _fileName
            End Get
            Set(ByVal value As String)
                Me._fileName = value
                _listBoxText = IO.Path.GetFileNameWithoutExtension(value)
            End Set
        End Property
        Sub New(ByVal FileName As String, Optional ByVal SkipTitleRequest As Boolean = True, Optional ByVal AlternateTitle As String = "")
            Me.Filename = FileName
            If Not SkipTitleRequest Then
                If Not AlternateTitle = "" Then
                    If ValidYoutubeURL(FileName) Then
                        Dim DisplayText As String = InputBox("Please enter a title for this youtube video.", "Enter media title.", "Youtube Video")
                        If DisplayText = "" Then
                            _listBoxText = "Youtube Video"
                        Else
                            _listBoxText = DisplayText
                        End If
                    End If
                End If
            Else
                If Not AlternateTitle = "" Then
                    Me._listBoxText = AlternateTitle
                End If
            End If
            If ValidYoutubeURL(FileName) Then
                Me.IsYoutubeObject = True
            End If
        End Sub
        Sub New()
    
        End Sub
        Public Overrides Function ToString() As String
            Return Me.ListBoxText
        End Function
        Function ValidYoutubeURL(ByVal URL As String) As Boolean
            If (URL.IndexOf("www.youtube.com") <> -1) Then Return True
            Return False
        End Function
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles



    • Edited by Paul Ishak Monday, December 24, 2012 7:39 PM
    Monday, December 24, 2012 7:33 PM

Answers

  • Did you include any of the SoapAttibutes in  the class?

    http://msdn.microsoft.com/en-us/library/system.xml.serialization.soapattributeattribute(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

    For example

    <SoapInclude(GetType(Vehicle))> _ Public Class Group

       <SoapAttribute (Namespace:= "http:'www.cpandl.com")> _
       Public GroupName As String   
       <SoapAttribute(DataType:= "base64Binary")> _
       Public GroupNumber() As  Byte

       <SoapAttribute(DataType:= "date", AttributeName:= "CreationDate")> _
       Public Today As DateTime
       <SoapElement(DataType:= "nonNegativeInteger", _
       ElementName:= "PosInt")> _
       Public PostitiveInt As String

       Public GroupVehicle As Vehicle
    End Class

    • Marked as answer by Paul Ishak Thursday, December 27, 2012 4:05 AM
    Thursday, December 27, 2012 1:57 AM
  • Ken, Thanks for the help, The problem had to do with the way I was writing my serialization sub, and I also did need to set some attributes. Thanks for all the help! Now lets cross our fingers and hope I get the de-serialization sub right!

        Sub SavePlayList(ByVal Filename As String)
            Dim PlaylistItems As New List(Of MyVideo)
            For Each Item In Listbox1.Items
                Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
                PlaylistItems.Add(MediaItem)
            Next
            Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
            Dim importer As New SoapReflectionImporter
            Dim mapping As XmlTypeMapping = importer.ImportTypeMapping(GetType(AvbMediaPlayerPlaylist))
            Dim writer As New XmlTextWriter(Filename, System.Text.Encoding.UTF8)
            writer.WriteStartElement("wrapper")
            writer.WriteAttributeString("xmlns", "xsd", Nothing, "http://www.w3.org/2001/SMLSchema")
            writer.WriteAttributeString("xmlns", "xsi", Nothing, "http://www.w3.org/2001/SMLSchema-instance")
            writer.WriteAttributeString("xmlns", "soap", Nothing, "http://schemas.xmlsoap.org/soap/encoding/")
            writer.WriteAttributeString("xmlns", "otherNS", Nothing, "urn:OtherNameSpace")
            Dim Serializer As New XmlSerializer(mapping)
            Serializer.Serialize(writer, PlayList)
            writer.WriteEndElement()
            writer.Close()
        End Sub

    <SoapType(TypeName:="aVbMediaPlayerPlaylist")> _
    <SoapInclude(GetType(MyVideo))> _
    Public Class AvbMediaPlayerPlaylist
        Public PlaylistMediaItems As New List(Of MyVideo)
        Sub New(ByVal PlayListItems As List(Of MyVideo))
            Me.PlaylistMediaItems = PlayListItems
        End Sub
        Sub New()
        End Sub
    End Class
    #End Region
    

    Option Strict On
    Imports System.Xml.Serialization
    <SoapType(TypeName:="aVbMediaPlayerPlaylistItem")> _
    Public Class MyVideo
        <SoapIgnore()>
        Public Property _fileName As String
        <SoapIgnore()>
        Public Property _listBoxText As String = String.Empty
        <SoapElement(isnullable:=True)> _
        Public Property IsYoutubeObject As Boolean = False
        <SoapElement(isnullable:=True)> _
        Public Property ArtworkPath As String = String.Empty
        <SoapElement(isnullable:=True)> _
        Public Property [Type] As ItemType
        <SoapElement(isnullable:=True)> _
            Public Property ListBoxText As String
            Get
                Return _listBoxText
            End Get
            Set(ByVal value As String)
                _listBoxText = value
            End Set
        End Property
        <SoapElement(isnullable:=True)> _
            Public Property Filename As String
            Get
                Return _fileName
            End Get
            Set(ByVal value As String)
                Me._fileName = value
            End Set
        End Property
        Sub New(ByVal FileName As String, Optional ByVal SkipTitleRequest As Boolean = True, Optional ByVal AlternateTitle As String = "")
            Me.Filename = FileName
            If Not SkipTitleRequest Then
                If AlternateTitle = "" Then
                    If ValidYoutubeURL(FileName) Then
                        Dim DisplayText As String = InputBox("Please enter a title for this youtube video.", "Enter media title.", "Youtube Video")
                        If DisplayText = "" Then
                            _listBoxText = "Youtube Video"
                        Else
                            _listBoxText = DisplayText
                        End If
                    End If
                End If
            Else
                If Not AlternateTitle = "" Then
                    Me._listBoxText = AlternateTitle
                End If
            End If
            If ValidYoutubeURL(FileName) Then
                Me.IsYoutubeObject = True
                Me.Type = ItemType.Youtube
            Else
                Dim Extension As String = LCase(FileName.Substring(FileName.Length - 3))
                Select Case Extension
                    Case "flv"
                        Me.Type = ItemType.Flv
                    Case "avi"
                        Me.Type = ItemType.Avi
                    Case "mp3"
                        Me.Type = ItemType.mp3
                    Case Else
                        Me.Type = ItemType.unknown
                End Select
            End If
            If _listBoxText = String.Empty Then
                _listBoxText = IO.Path.GetFileNameWithoutExtension(FileName)
            End If
        End Sub
        Sub New()
        End Sub
        Public Overrides Function ToString() As String
            Return Me.ListBoxText
        End Function
        Function ValidYoutubeURL(ByVal URL As String) As Boolean
            If (URL.ToLower.IndexOf("www.youtube.com") <> -1) Then Return True
            Return False
        End Function
        Public Enum ItemType
            <SoapEnum(name:="Youtube")>
            Youtube = 0
            <SoapEnum(name:="AVI")>
            Avi = 1
            <SoapEnum(name:="FLV")>
            Flv = 2
            <SoapEnum(name:="MP3")>
            mp3 = 3
            <SoapEnum(name:="Unknown")>
            unknown = 99
        End Enum
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    • Marked as answer by Paul Ishak Thursday, December 27, 2012 4:05 AM
    Thursday, December 27, 2012 4:05 AM

All replies

  • I also want to add that I am relatively new to serialization. I don't get any problems if I serialize to standard xml(and it will probably work just fine for my app), but I was hoping to test out the soap formatter, and that is where I got the error above...

        Sub SavePlayList(ByVal Filename As String)
            Dim PlaylistItems As New List(Of MyVideo)
            For Each Item In ListBox1.Items
                Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
                PlaylistItems.Add(MediaItem)
            Next
            Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
            Dim Serializer As New Xml.Serialization.XmlSerializer(GetType(AvbMediaPlayerPlaylist))
            Using sw As New StreamWriter(Filename)
                Serializer.Serialize(sw, PlayList)
            End Using
        End Sub



    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Monday, December 24, 2012 8:04 PM
  • Paul,

    Help me understand why you are serializing.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me

    Monday, December 24, 2012 8:43 PM
  • Paul,

    Help me understand why you are serializing.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me

    Well, mainly because I need the practice, I can get standard xml serialization to work fine, but when I follow the example in my book for soap serialization, I get the error above... There must be something I'm missing, but I don't see it!


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Monday, December 24, 2012 8:47 PM
  • Did you include any of the SoapAttibutes in  the class?

    http://msdn.microsoft.com/en-us/library/system.xml.serialization.soapattributeattribute(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

    For example

    <SoapInclude(GetType(Vehicle))> _ Public Class Group

       <SoapAttribute (Namespace:= "http:'www.cpandl.com")> _
       Public GroupName As String   
       <SoapAttribute(DataType:= "base64Binary")> _
       Public GroupNumber() As  Byte

       <SoapAttribute(DataType:= "date", AttributeName:= "CreationDate")> _
       Public Today As DateTime
       <SoapElement(DataType:= "nonNegativeInteger", _
       ElementName:= "PosInt")> _
       Public PostitiveInt As String

       Public GroupVehicle As Vehicle
    End Class

    • Marked as answer by Paul Ishak Thursday, December 27, 2012 4:05 AM
    Thursday, December 27, 2012 1:57 AM
  • Did you include any of the SoapAttibutes in  the class?

    Thanks for your response Ken,

    I have not done that, I will give it a go, and come back shortly to let you know the result.


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Thursday, December 27, 2012 2:01 AM
  • I'm still getting errors!!!!

    'ItemType' is an invalid value for the SoapElementAttribute.DataType property. The property may only be specified for primitive types.

        Sub SavePlayList(ByVal Filename As String)
            Dim PlaylistItems As New List(Of MyVideo)
            For Each Item In Listbox1.Items
                Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
                PlaylistItems.Add(MediaItem)
            Next
            Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
            Dim SoapMapping As Xml.Serialization.XmlTypeMapping = _
              (New Xml.Serialization.SoapReflectionImporter).ImportTypeMapping(GetType(AvbMediaPlayerPlaylist))
            Dim Serializer As New Xml.Serialization.XmlSerializer(SoapMapping)
    
            Using sw As New StreamWriter(Filename)
                Serializer.Serialize(sw, PlayList)
            End Using
        End Sub

    Option Strict On
    Imports System.Xml.Serialization
    Public Class MyVideo
        <SoapAttribute(DataType:="string", AttributeName:="FileNameUrl")> _
        Public _fileName As String
        <SoapAttribute(DataType:="string", AttributeName:="DisplayText")> _
        Public Property _listBoxText As String = String.Empty
        <SoapAttribute(DataType:="boolean", AttributeName:="IsYoutubeObject")> _
        Public Property IsYoutubeObject As Boolean = False
        <SoapAttribute(DataType:="string", AttributeName:="ArtworkPath")> _
        Public Property ArtworkPath As String = String.Empty
        <SoapAttribute(DataType:="ItemType", AttributeName:="ItemType")> _
        Public Property [Type] As ItemType
        <SoapIgnore()>
        Public Property ListBoxText As String
            Get
                Dim a As System.Int32
                Return _listBoxText
            End Get
            Set(ByVal value As String)
                _listBoxText = value
            End Set
        End Property
        <SoapIgnore()>
        Public Property Filename As String
            Get
                Return _fileName
            End Get
            Set(ByVal value As String)
                Me._fileName = value
            End Set
        End Property
        Sub New(ByVal FileName As String, Optional ByVal SkipTitleRequest As Boolean = True, Optional ByVal AlternateTitle As String = "")
            Me.Filename = FileName
            If Not SkipTitleRequest Then
                If AlternateTitle = "" Then
                    If ValidYoutubeURL(FileName) Then
                        Dim DisplayText As String = InputBox("Please enter a title for this youtube video.", "Enter media title.", "Youtube Video")
                        If DisplayText = "" Then
                            _listBoxText = "Youtube Video"
                        Else
                            _listBoxText = DisplayText
                        End If
                    End If
                End If
            Else
                If Not AlternateTitle = "" Then
                    Me._listBoxText = AlternateTitle
                End If
            End If
            If ValidYoutubeURL(FileName) Then
                Me.IsYoutubeObject = True
                Me.Type = ItemType.Youtube
            Else
                Dim Extension As String = LCase(FileName.Substring(FileName.Length - 3))
                Select Case Extension
                    Case "flv"
                        Me.Type = ItemType.Flv
                    Case "avi"
                        Me.Type = ItemType.Avi
                    Case "mp3"
                        Me.Type = ItemType.mp3
                    Case Else
                        Me.Type = ItemType.unknown
                End Select
            End If
            If _listBoxText = String.Empty Then
                _listBoxText = IO.Path.GetFileNameWithoutExtension(FileName)
            End If
        End Sub
        Sub New()
    
        End Sub
        Public Overrides Function ToString() As String
            Return Me.ListBoxText
        End Function
        Function ValidYoutubeURL(ByVal URL As String) As Boolean
            If (URL.ToLower.IndexOf("www.youtube.com") <> -1) Then Return True
            Return False
        End Function
        Public Enum ItemType
            Youtube = 0
            Avi = 1
            Flv = 2
            mp3 = 3
            unknown = 99
        End Enum
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Thursday, December 27, 2012 2:56 AM
  • I skipped tagging that item, And in the end I get the same error!!!

    {"Token StartElement in state Epilog would result in an invalid XML document."}

    What is this error??


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    Thursday, December 27, 2012 3:03 AM
  • Ken, Thanks for the help, The problem had to do with the way I was writing my serialization sub, and I also did need to set some attributes. Thanks for all the help! Now lets cross our fingers and hope I get the de-serialization sub right!

        Sub SavePlayList(ByVal Filename As String)
            Dim PlaylistItems As New List(Of MyVideo)
            For Each Item In Listbox1.Items
                Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
                PlaylistItems.Add(MediaItem)
            Next
            Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
            Dim importer As New SoapReflectionImporter
            Dim mapping As XmlTypeMapping = importer.ImportTypeMapping(GetType(AvbMediaPlayerPlaylist))
            Dim writer As New XmlTextWriter(Filename, System.Text.Encoding.UTF8)
            writer.WriteStartElement("wrapper")
            writer.WriteAttributeString("xmlns", "xsd", Nothing, "http://www.w3.org/2001/SMLSchema")
            writer.WriteAttributeString("xmlns", "xsi", Nothing, "http://www.w3.org/2001/SMLSchema-instance")
            writer.WriteAttributeString("xmlns", "soap", Nothing, "http://schemas.xmlsoap.org/soap/encoding/")
            writer.WriteAttributeString("xmlns", "otherNS", Nothing, "urn:OtherNameSpace")
            Dim Serializer As New XmlSerializer(mapping)
            Serializer.Serialize(writer, PlayList)
            writer.WriteEndElement()
            writer.Close()
        End Sub

    <SoapType(TypeName:="aVbMediaPlayerPlaylist")> _
    <SoapInclude(GetType(MyVideo))> _
    Public Class AvbMediaPlayerPlaylist
        Public PlaylistMediaItems As New List(Of MyVideo)
        Sub New(ByVal PlayListItems As List(Of MyVideo))
            Me.PlaylistMediaItems = PlayListItems
        End Sub
        Sub New()
        End Sub
    End Class
    #End Region
    

    Option Strict On
    Imports System.Xml.Serialization
    <SoapType(TypeName:="aVbMediaPlayerPlaylistItem")> _
    Public Class MyVideo
        <SoapIgnore()>
        Public Property _fileName As String
        <SoapIgnore()>
        Public Property _listBoxText As String = String.Empty
        <SoapElement(isnullable:=True)> _
        Public Property IsYoutubeObject As Boolean = False
        <SoapElement(isnullable:=True)> _
        Public Property ArtworkPath As String = String.Empty
        <SoapElement(isnullable:=True)> _
        Public Property [Type] As ItemType
        <SoapElement(isnullable:=True)> _
            Public Property ListBoxText As String
            Get
                Return _listBoxText
            End Get
            Set(ByVal value As String)
                _listBoxText = value
            End Set
        End Property
        <SoapElement(isnullable:=True)> _
            Public Property Filename As String
            Get
                Return _fileName
            End Get
            Set(ByVal value As String)
                Me._fileName = value
            End Set
        End Property
        Sub New(ByVal FileName As String, Optional ByVal SkipTitleRequest As Boolean = True, Optional ByVal AlternateTitle As String = "")
            Me.Filename = FileName
            If Not SkipTitleRequest Then
                If AlternateTitle = "" Then
                    If ValidYoutubeURL(FileName) Then
                        Dim DisplayText As String = InputBox("Please enter a title for this youtube video.", "Enter media title.", "Youtube Video")
                        If DisplayText = "" Then
                            _listBoxText = "Youtube Video"
                        Else
                            _listBoxText = DisplayText
                        End If
                    End If
                End If
            Else
                If Not AlternateTitle = "" Then
                    Me._listBoxText = AlternateTitle
                End If
            End If
            If ValidYoutubeURL(FileName) Then
                Me.IsYoutubeObject = True
                Me.Type = ItemType.Youtube
            Else
                Dim Extension As String = LCase(FileName.Substring(FileName.Length - 3))
                Select Case Extension
                    Case "flv"
                        Me.Type = ItemType.Flv
                    Case "avi"
                        Me.Type = ItemType.Avi
                    Case "mp3"
                        Me.Type = ItemType.mp3
                    Case Else
                        Me.Type = ItemType.unknown
                End Select
            End If
            If _listBoxText = String.Empty Then
                _listBoxText = IO.Path.GetFileNameWithoutExtension(FileName)
            End If
        End Sub
        Sub New()
        End Sub
        Public Overrides Function ToString() As String
            Return Me.ListBoxText
        End Function
        Function ValidYoutubeURL(ByVal URL As String) As Boolean
            If (URL.ToLower.IndexOf("www.youtube.com") <> -1) Then Return True
            Return False
        End Function
        Public Enum ItemType
            <SoapEnum(name:="Youtube")>
            Youtube = 0
            <SoapEnum(name:="AVI")>
            Avi = 1
            <SoapEnum(name:="FLV")>
            Flv = 2
            <SoapEnum(name:="MP3")>
            mp3 = 3
            <SoapEnum(name:="Unknown")>
            unknown = 99
        End Enum
    End Class


    If you want something you've never had, you need to do something you've never done.

    Everyone should take the time to mark helpful posts and propose answers!

    Answer an interesting question?
    Create a wiki article about it!

    My Technet Wiki Articles

    • Marked as answer by Paul Ishak Thursday, December 27, 2012 4:05 AM
    Thursday, December 27, 2012 4:05 AM