webclient 下载C# codeUri url new Uri(http://localhost:2215/2.rar)WebClient client new WebCli
webclient 下载
C# codeUri url = new Uri("http://localhost:2215/2.rar");WebClient client = new WebClient();client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); client.OpenReadAsync(url);void client_OpenReadCompleted(object obj, OpenReadCompletedEventArgs e) { if (e.Error == null) { Stream stream = e.Result; byte[] by = new byte[stream.Length + 1]; stream.Read(by, 0, by.Length); FileStream fs = new FileStream("C:\\aa.rar", FileMode.CreateNew,FileAccess.Write); fs.Write(by, 0, by.Length); fs.Flush(); fs.Close(); } }
试图访问该方法时失败:
System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess)
不知道怎么解决 本人刚学SL 什么都不清楚
[解决办法]C:\\aa.rar,
不能操作本地文件系统,
[解决办法]void client_OpenReadCompleted(object obj, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
Stream stream = e.Result;
byte[] by = new byte[stream.Length + 1];
stream.Read(by, 0, by.Length);
FileStream fs = new FileStream("C:\\aa.rar", FileMode.CreateNew,FileAccess.Write);
fs.Write(by, 0, by.Length);
fs.Flush();
fs.Close();
}
}
Silverlight 2&3,作为客户端没有权限访问本地磁盘,你可以使用WCF或者Webservice,传递参数到服务器端进行存取处理。
Silverlight 4中允许客户端对本地文件访问。