I need to write a web application that allows the client to download a file from the server, so far so good, but the file must be kind of encoded, so i need to decode it on the client and write it on a file on the client's PC.
我需要编写一个允许客户端从服务器下载文件的Web应用程序,到目前为止一直很好,但文件必须是一种编码,所以我需要在客户端解码它并将其写在一个文件上客户的PC。
Can i do this using Silverlight? and how?
我可以使用Silverlight吗?如何?
If it is not possible, there is another way to do it?. Any suggestions?
如果不可能,还有另一种方法吗?有什么建议?
Thanks
Edit: As exposed for Brian Genisio, i can ask for user permision to save the file, so i think that the open and save Dialogs are ok for my case. But in case that that's not enough, is there a way to, with or without user interaction, to save the file outside of the isolated storage, for example emulating a new download for the user?
编辑:为Brian Genisio公开,我可以要求用户权限保存文件,所以我认为打开和保存对话框对我的情况是好的。但是,如果这还不够,有没有办法在有或没有用户交互的情况下将文件保存在隔离存储之外,例如为用户模拟新的下载?
5 个解决方案
#1
In Silverlight 3.0, you will have access to read and write files via the OpenFileDialog. In Silverlight 2.0, you have access to Isolated Sotrage, which will let you save to a sandbox. You will probably never have full access to the file system without user permission, though.
在Silverlight 3.0中,您可以通过OpenFileDialog访问读取和写入文件。在Silverlight 2.0中,您可以访问Isolated Sotrage,它可以保存到沙箱中。但是,如果没有用户权限,您可能永远不会拥有对文件系统的完全访问权限。
#2
You can use IsolatedStorageFile Class for this using silverlight.
您可以使用Silverlight来使用IsolatedStorageFile类。
Another link: How to Read and Write files in the Isolated Storage?
另一个链接:如何在隔离存储中读写文件?
#3
You cannot do this for security reasons:
出于安全原因,您无法执行此操作:
Silverlight-based applications do not use the file system of the operating system and are restricted to using isolated storage to persist and access files, so this namespace [System.IO] does not provide any additional functionality. For more information about how Silverlight-based applications use isolated storage, see Isolated Storage.
基于Silverlight的应用程序不使用操作系统的文件系统,并且仅限于使用隔离存储来持久存取和访问文件,因此此命名空间[System.IO]不提供任何其他功能。有关基于Silverlight的应用程序如何使用隔离存储的详细信息,请参阅隔离存储。
If possible, you might want to shift it such that the server does the encoding and the file is made available for download in a traditional manner.
如果可能,您可能希望将其移位,使服务器执行编码,并以传统方式使文件可供下载。
If you're encoding for privacy/security consider offering the download only on a secure protocol (HTTPS using SSL).
如果您要进行隐私/安全编码,请考虑仅使用安全协议(使用SSL的HTTPS)提供下载。
#4
Another option (not elegant but works) could be to perform a ping pong using services:
另一种选择(不优雅但有效)可以使用服务执行乒乓:
- Get the file from the server.
- Perform the encoding /transformation you need on the client side.
- Send it to the server again using a WCF service, store it in session.
- Call a javascript method from SL that will make a request to a custom HTTP hanlder.
- That custom HTTP hanlder would return the file that was in session as an attachment (first time the nasty bar from IE would appear... you are going to download something...).
从服务器获取文件。
在客户端执行所需的编码/转换。
使用WCF服务再次将其发送到服务器,将其存储在会话中。
从SL调用一个javascript方法,该方法将向自定义HTTP hanlder发出请求。
那个自定义的HTTP hanlder会将会话中的文件作为附件返回(第一次出现IE的讨厌栏吧......你要下载的东西......)。
My case is a bit simpler, in my application I needed to export a DB Diagram to JPEG and to perform an export as well to an HTML report, I used that approach (ping pong :)).
我的情况稍微简单一些,在我的应用程序中我需要将DB Diagram导出为JPEG并执行导出以及HTML报告,我使用了这种方法(ping pong :))。
If you want to take a look:
如果你想看看:
HTH Braulio
#5
With Silverlight 4, you can do this in a primitive way by using AutomationFactory to automate a FileSystemObject.
使用Silverlight 4,您可以使用AutomationFactory自动化FileSystemObject以原始方式执行此操作。
see: http://justinangel.net/CuttingEdgeSilverlight4ComFeatures#BlogPost=CuttingEdgeSilverlight4ComFeat
#1
In Silverlight 3.0, you will have access to read and write files via the OpenFileDialog. In Silverlight 2.0, you have access to Isolated Sotrage, which will let you save to a sandbox. You will probably never have full access to the file system without user permission, though.
在Silverlight 3.0中,您可以通过OpenFileDialog访问读取和写入文件。在Silverlight 2.0中,您可以访问Isolated Sotrage,它可以保存到沙箱中。但是,如果没有用户权限,您可能永远不会拥有对文件系统的完全访问权限。
#2
You can use IsolatedStorageFile Class for this using silverlight.
您可以使用Silverlight来使用IsolatedStorageFile类。
Another link: How to Read and Write files in the Isolated Storage?
另一个链接:如何在隔离存储中读写文件?
#3
You cannot do this for security reasons:
出于安全原因,您无法执行此操作:
Silverlight-based applications do not use the file system of the operating system and are restricted to using isolated storage to persist and access files, so this namespace [System.IO] does not provide any additional functionality. For more information about how Silverlight-based applications use isolated storage, see Isolated Storage.
基于Silverlight的应用程序不使用操作系统的文件系统,并且仅限于使用隔离存储来持久存取和访问文件,因此此命名空间[System.IO]不提供任何其他功能。有关基于Silverlight的应用程序如何使用隔离存储的详细信息,请参阅隔离存储。
If possible, you might want to shift it such that the server does the encoding and the file is made available for download in a traditional manner.
如果可能,您可能希望将其移位,使服务器执行编码,并以传统方式使文件可供下载。
If you're encoding for privacy/security consider offering the download only on a secure protocol (HTTPS using SSL).
如果您要进行隐私/安全编码,请考虑仅使用安全协议(使用SSL的HTTPS)提供下载。
#4
Another option (not elegant but works) could be to perform a ping pong using services:
另一种选择(不优雅但有效)可以使用服务执行乒乓:
- Get the file from the server.
- Perform the encoding /transformation you need on the client side.
- Send it to the server again using a WCF service, store it in session.
- Call a javascript method from SL that will make a request to a custom HTTP hanlder.
- That custom HTTP hanlder would return the file that was in session as an attachment (first time the nasty bar from IE would appear... you are going to download something...).
从服务器获取文件。
在客户端执行所需的编码/转换。
使用WCF服务再次将其发送到服务器,将其存储在会话中。
从SL调用一个javascript方法,该方法将向自定义HTTP hanlder发出请求。
那个自定义的HTTP hanlder会将会话中的文件作为附件返回(第一次出现IE的讨厌栏吧......你要下载的东西......)。
My case is a bit simpler, in my application I needed to export a DB Diagram to JPEG and to perform an export as well to an HTML report, I used that approach (ping pong :)).
我的情况稍微简单一些,在我的应用程序中我需要将DB Diagram导出为JPEG并执行导出以及HTML报告,我使用了这种方法(ping pong :))。
If you want to take a look:
如果你想看看:
HTH Braulio
#5
With Silverlight 4, you can do this in a primitive way by using AutomationFactory to automate a FileSystemObject.
使用Silverlight 4,您可以使用AutomationFactory自动化FileSystemObject以原始方式执行此操作。
see: http://justinangel.net/CuttingEdgeSilverlight4ComFeatures#BlogPost=CuttingEdgeSilverlight4ComFeat