如何在wp7中将字节数组写入服务器中的文本文件

时间:2012-07-11 12:55:56

标签: windows-phone-7

我想在服务器代码运行时将字节数组写入txt文件但是它没有在服务器文件上显示任何内容。 我该怎么写呢

private void button1_Click(object sender, RoutedEventArgs e)
{
    Stream mystream = Application.GetResourceStream(new Uri(@"LoadVideo;component/test.mp4", UriKind.Relative)).Stream;

    byte[] myarray = new byte[mystream.Length];
    int bytesRead = mystream.Read(myarray, 0, (int)mystream.Length);

    mystream.Close();

    WebClient wc = new WebClient();
    wc.OpenWriteCompleted += new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);


    Uri u = new Uri("http://xyz/New.txt");
    wc.OpenWriteAsync(u, null, new object[] { myarray, bytesRead }); // Upload the file to the server
}

void wc_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) // The upload completed
{
    if (e.Error == null)
    {
        // Upload completed without error
    }
}

我的代码是否正确?请提出任何建议。

1 个答案:

答案 0 :(得分:0)

我会使用socket。这是一个例子: WP7 socket tutorial