首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

wince 下载文件,模拟器路径始终找不到解决方案

2012-06-01 
wince 下载文件,模拟器路径始终找不到string fromPath http://www.red-ambers.com/exchange/ad/vanke/1

wince 下载文件,模拟器路径始终找不到
string fromPath = "http://www.red-ambers.com/exchange/ad/vanke/1202/music/xingxing.mp3?h=e1ojmcenj8yZXl0f13AEsQ&e=1329124910"; //源文件路径
  //目标路径
  string downPath =Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)+"\\test.mp3";
  string downPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
  private void button1_Click(object sender, EventArgs e)
  {
  try
  {
  MessageBox.Show(downPath);
  //create web request/response
  HttpWebResponse Response;
  HttpWebRequest Request;
  Request = (HttpWebRequest)HttpWebRequest.Create(fromPath);
  Request.Headers.Add("Translate: f");
  Request.Credentials = CredentialCache.DefaultCredentials;

  Response = (HttpWebResponse)Request.GetResponse();



  Stream respStream = null;
  respStream = Response.GetResponseStream();

  int FileSize = int.Parse(Response.ContentLength.ToString());
  //int FileSize = int.Parse(System.Convert.ToInt64(Response.Headers["Content-Length"]).ToString());

  //Do the Download
  byte[] buffer = new byte[FileSize];
  FileStream fs = File.Open(downPath, FileMode.Create, FileAccess.Write);
  int length;
  length = respStream.Read(buffer, 0, FileSize);
  long writeLength = length;
  while (length != 0)
  {
  fs.Write(buffer, 0, length);
  length = respStream.Read(buffer, 0, FileSize);
  writeLength += (long)length;
  }
  fs.Close();
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString(), "Error");

  }

程序走到“FileStream fs = File.Open(downPath, FileMode.Create, FileAccess.Write);”这一步的时候,控制台就会出现如下错误,
在 System.IO.FileNotFoundException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.IO.FileNotFoundException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.UriFormatException 中第一次偶然出现的“System.dll”类型的异常

感觉应该是模拟器路径不对,但是改过来改过去,怎么地就是不好用,唉。。。。。

[解决办法]
先试试将文件路径写死,例如:\\test.mp3,看看会不会报错?

热点排行