简体   繁体   中英

How to save file on local machine in silverlight 4.0?

I am downloading the file using server file path and want to save file on local machine? But I am stuck in silver light because I am new in this..

Any Help....

You can save files (1 at a time) by using the SaveFileDialog. Because of security, this is the only way you can write files to the local HD.

Private textDialog As SaveFileDialog
Public Sub New()
    InitializeComponent()
    textDialog = New SaveFileDialog()
    textDialog.Filter = "Text Files | *.txt"
    textDialog.DefaultExt = "txt"
End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim result As System.Nullable(Of Boolean) = textDialog.ShowDialog()
    If result = True Then
        Dim fileStream As System.IO.Stream = textDialog.OpenFile()
        Dim sw As New System.IO.StreamWriter(fileStream)
        sw.WriteLine("Writing some text in the file.")
        sw.Flush()
        sw.Close()
    End If
End Sub

Reference: MSDN

Silverlight runs in a sandbox - this limits its ability to read/write files to the drive.

This is a security feature, Users are allowed to open files through use of the OpenFileDialog, but there is no Save feature.

The only way of saving to the users drive is to write what you want to the server and let the user download it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM