如何构建将音频文件下载到本地文件夹或从 silverlight 应用程序下载文件夹的功能?

How to build a functionality to download Audio files to local folder or downloads folder from a silverlight application?

我有一个 silverlight 网络应用程序,其中我有播放 audio/sound files.Currently 声音文件的功能存储在 Client Bin 文件夹中,声音文件可以在 server.I 想要构建一个功能 将这些声音文件下载到用户电脑。 我尝试使用保存文件对话框,但无法下载音频文件。

试试这个 webclient methods not available to my Silverlight application

You can best achieve what you want in Silverlight by using WebClient.OpenReadCompleted and OpenReadAsync. This will return a stream. You can use that directly, or copy the stream into a byte[] as described here for example: http://www.yoda.arachsys.com/csharp/readbinary.html

解决方案是- 我从服务器的客户端 bin 文件夹中获取音频文件,然后使用保存文件对话框将其下载到客户端机器上的本地文件夹。 如下-

 Private Sub btn_downloadSound_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
    If streamAudio_download Is Nothing Then
        MessageBox.Show("Audio file does not exists for selected sound feature")
    Else
        saveFileDialog1.Filter = "MP3 Files (*.mp3)|*.mp3|MP4 Files|*.mp4"
        saveFileDialog1.ShowDialog()
        Dim words As String() = soundFileSelected_Name.Split(".")
        Dim fileExtension As String = words(1)
        Using audiofs As System.IO.FileStream = saveFileDialog1.OpenFile()
            If fileExtension = "mp3" Then
                Dim bytes As Byte() = New Byte(40) {}
                Dim bytesToRead As Integer = 0
                bytesToRead = streamAudio_download.Read(bytes, 0, bytes.Length)

                While (bytesToRead = streamAudio_download.Read(bytes, 0, bytes.Length)) <> 0
                    audiofs.Write(bytes, 0, bytesToRead)
                End While
            ElseIf fileExtension = "mp4" Then
                Dim b As New BinaryWriter(audiofs)
                b.Write(byteArray)
                audiofs.Close()
            End If
        End Using
    End If
End Sub