WebClient.UploadFileAsync - 上传完成后删除
我正在使用此代码将文件异步上传到我的网络服务器。
WebClient fileUploader = new WebClient();
fileUploader.UploadFileCompleted += new UploadFileCompletedEventHandler(fileUploader_Completed);
fileUploader.UploadFileAsync(new Uri("http://www.example.com/upload.php"), "POST", @"C:\foo\bar.txt");
我想在上传后从磁盘中删除该文件。我可以通过某种方式将本地文件名传递给 UploadFileCompletedEventHandler 吗?感谢您的帮助!
I'm using this code to upload files asynchronously to my web server.
WebClient fileUploader = new WebClient();
fileUploader.UploadFileCompleted += new UploadFileCompletedEventHandler(fileUploader_Completed);
fileUploader.UploadFileAsync(new Uri("http://www.example.com/upload.php"), "POST", @"C:\foo\bar.txt");
I want to remove the file from disk after uploading. Can I pass the local filename to the UploadFileCompletedEventHandler in some way? Thanks for helping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 UploadFileAsync 的另一个重载 - http://msdn.microsoft.com/en-us /library/ms144234.aspx 接受 userToken 参数。您将在完整处理程序中以 AsyncCompletedEventArgs.UserState 形式接收该参数。
示例位于 - http://msdn.microsoft.com/en -us/library/system.net.uploadfilecompletedeventhandler.aspx
Use anoter overload of UploadFileAsync - http://msdn.microsoft.com/en-us/library/ms144234.aspx that takes userToken argument. You'll receve that argument as AsyncCompletedEventArgs.UserState in complete handler.
Sample available at - http://msdn.microsoft.com/en-us/library/system.net.uploadfilecompletedeventhandler.aspx