简体   繁体   English

如何在Silverlight 4.0中将文件保存在本地计算机上?

[英]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. 您可以使用SaveFileDialog保存文件(一次保存1个)。 Because of security, this is the only way you can write files to the local HD. 由于安全原因,这是将文件写入本地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 参考: MSDN

Silverlight runs in a sandbox - this limits its ability to read/write files to the drive. Silverlight在沙箱中运行-这限制了它读取/写入驱动器文件的能力。

This is a security feature, Users are allowed to open files through use of the OpenFileDialog, but there is no Save feature. 这是一项安全功能,允许用户使用OpenFileDialog打开文件,但没有保存功能。

The only way of saving to the users drive is to write what you want to the server and let the user download it. 保存到用户驱动器的唯一方法是将所需内容写入服务器,然后让用户下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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