我根據示例1爲.NET Framework 2製作了我的程序,但我將其轉換爲.NET Framework 3.5。我應該如何修改此代碼才能使其工作?我怎樣才能調試服務器端?服務器端似乎工作時,我手動插入參數到URL,所以問題必須在客戶端代碼。WebClient未連接到IHttpHandler
private void UploadFile(string fileName, System.IO.Stream data)
{
UriBuilder ub = new UriBuilder("http://localhost:59491/receiver.ashx");
ub.Query = string.Format("filename={0}", fileName);
WebClient c = new WebClient();
c.OpenWriteCompleted += (sender, e) =>
{
PushData(data, e.Result);
e.Result.Close();
data.Close();
};
c.OpenWriteAsync(ub.Uri);
}
private void PushData(System.IO.Stream input, System.IO.Stream output)
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
{
output.Write(buffer, 0, bytesRead);
}
}
1http://www.c-sharpcorner.com/UploadFile/nipuntomar/FileUploadsilverlight03182009030537AM/FileUploadsilverlight.aspx