询问者
Throw FileNotFoundException when upload file to onedrive

问题
全部回复
-
你好 Luke,
准确来说你的这个问题已经不属于Windows Store App范畴之内,因为是使用的Live的API上传文件的吧。
不过从你的叙述来看,代码应该没有问题,毕竟你说sometimes it works well,这样的话我会比较推荐你去确认以下几个事项:
1,本地文件是否存在,并且有权限访问 (FileNotFound一般都是这里出现)
2,网络是否随时保证畅通
3,OneDrive上是否有足够的空间上传
或者你的程序里面还有提示其他什么样的信息么,当然你也可以监测一下当出现问题时候的系统环境如何,是否有文件存在之类的。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
Thanks, James
可以确定的是,本地文件是存在的,并且有访问权限,OneDrive也有足够的空间上传,网络方面也比较畅通
抛出的异常信息如下:
System.IO.FileNotFoundException was caught
HResult=-2147024894
Message=The system cannot find the file specified. (HRESULT からの例外:0x80070002)
Source=mscorlib
StackTrace:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Live.LiveUploadOperation.<ExecuteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at FileUploadDownload.MainPage.<btnSelectUploadFile_Click>d__f.MoveNext()
InnerException:
所以我推测有可能是上传的API读取传入的文件后,又创建了一个缓存文件,对缓存文件的操作出现了问题,或者这个异常其实指的是OneDrive上的文件找不到?
Best Regards,
Luke
-
Hi Luke,
不好意思,我也不清楚这个API内部是怎么运行的,你可以贴一段代码让我看看吗?是否有用到异步之类的?我认为你还可以测试一下不同大小的文件,比如说小于某个值的必然会成功,大于某个值的要看机器性能之类的。
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later. -
Hi, James
关于不同的文件的问题,我也有测试,看起来与文件大小、类型等没有什么关系。
非常抱歉,我本想贴一段代码,但提示超出字符数了。
我使用MS放在Github上的sample code测试,这个问题依然会概率性的出现,代码地址如下:
https://github.com/liveservices/LiveSDK-for-Windows/blob/master/src/WinStore/Samples/Windows/XAML/FileUploadDownload/MainPage.xaml.cs
非常感谢您的关注
Best Regards,
Luke
-
你好 Luke,
尝试吧Try Catch去掉看看具体错误出现在哪里?下面这段代码是Try部分的,可能出现问题的就在加黑的部分。
string folderPath = this.tbuploadUrl.Text; var picker = new FileOpenPicker { ViewMode = PickerViewMode.Thumbnail, SuggestedStartLocation = PickerLocationId.PicturesLibrary }; picker.FileTypeFilter.Add("*"); StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { this.fileName = file.Name; this.progressBar.Value = 0; var progressHandler = new Progress<LiveOperationProgress>( (progress) => { this.progressBar.Value = progress.ProgressPercentage; }); this.ShowProgress(); this.cts = new CancellationTokenSource(); LiveUploadOperation operation = await this.liveClient.CreateBackgroundUploadAsync( folderPath, file.Name, file, OverwriteOption.Rename); LiveOperationResult result = await operation.StartAsync( this.cts.Token, progressHandler); dynamic fileData = result.Result; string downloadUrl = fileData.id + "/content"; this.tbdownloadUrl.Text = downloadUrl; this.ShowMessage("Upload completed"); }
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.