silverlight webclient读文件问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Uri handlerUri = new Uri("/Docs/HTMLPage1.html", UriKind.Relative);
WebClient client = new WebClient();
client.OpenReadAsync(handlerUri);
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
}
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message, "加载信息详情错误", MessageBoxButton.OK);
}
else
{
MessageBox.Show(e.Result.Length.ToString());
}
}
}
}
/Docs/HTMLPage1.html 项目里已经有文件了 clientbin里也拷了一份
为什么总报no found
[解决办法]
Uri handlerUri = new Uri("/Docs/HTMLPage1.html", UriKind.Relative);
最前面的'/'去掉,Docs/HTMLPage1.html
改成
Uri handlerUri = new Uri("Docs/HTMLPage1.html", UriKind.Relative);