首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

silverlight webclient读文件有关问题

2012-04-17 
silverlight webclient读文件问题using Systemusing System.Collections.Genericusing System.Linqusin

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);

热点排行