C# 为什么我能';是否无法将sqlite文件上载到OneDrive?

C# 为什么我能';是否无法将sqlite文件上载到OneDrive?,c#,sqlite,windows-runtime,win-universal-app,onedrive,C#,Sqlite,Windows Runtime,Win Universal App,Onedrive,我正在开发一个Windows运行时通用应用程序 我需要将应用程序中使用的数据库上载到用户的OneDrive 但是发生了FileNotFound异常。但我知道这条路是正确的 因为我引用了sqlite文件,所以它显示了异常。若我参考了txt文件,上传过程会很顺利 var authClient = new LiveAuthClient(); var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.sk

我正在开发一个Windows运行时通用应用程序

我需要将应用程序中使用的数据库上载到用户的OneDrive

但是发生了
FileNotFound
异常。但我知道这条路是正确的

因为我引用了sqlite文件,所以它显示了异常。若我参考了txt文件,上传过程会很顺利

var authClient = new LiveAuthClient();
var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
if (authResult.Session != null)
{
    var liveConnectClient = new LiveConnectClient(authResult.Session);
    var FileToUpload = await ApplicationData.Current.LocalFolder.GetFileAsync("text.sqlite");//exception occurs here        
    var FileToUpload = await ApplicationData.Current.LocalFolder.GetFileAsync("text.txt");//no exception for txt files

    var folderData = new Dictionary<string, object>();
    folderData.Add("name", "Folder") 
    LiveOperationResult operationResult = await liveConnectClient.PostAsync("me/skydrive", folderData);

    LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(folderId, "filename", FileToUpload, OverwriteOption.Overwrite);
    LiveOperationResult uploadResult = await uploadOperation.StartAsync();
    HandleUploadResult(uploadResult);
}
var-authClient=new-LiveAuthClient();
var authResult=wait authClient.LoginAsync(新字符串[]{“wl.skydrive”,“wl.skydrive_update”});
if(authResult.Session!=null)
{
var liveConnectClient=新的liveConnectClient(authResult.Session);
var FileToUpload=wait ApplicationData.Current.LocalFolder.GetFileAsync(“text.sqlite”);//此处发生异常
var FileToUpload=wait ApplicationData.Current.LocalFolder.GetFileAsync(“text.txt”);//txt文件不例外
var folderData=新字典();
添加(“名称”、“文件夹”)
LiveOperationResult operationResult=等待liveConnectClient.PostAsync(“me/skydrive”,folderData);
LiveUploadOperation uploadOperation=等待liveConnectClient.CreateBackgroundUploadAsync(folderId,“filename”,FileToUpload,OverwriteOption.Overwrite);
LiveOperationResult uploadResult=等待上载操作。StartAsync();
HandleUploadResult(上传结果);
}

首先,您应该使用后台传输任务来移动这么大的文件,并处理用户在传输过程中接到呼叫的情况。背景任务是关键

有点像这样

BackgroundUploader uploader = new BackgroundUploader(); 
UploadOperation upload = uploader.CreateUpload(uri, file); 
await HandleUploadAsync(upload, true); 
但在您这样做之前,您需要假设用户将操纵数据库。因此,您应该在开始上载之前复制数据库文件。同样,代码:

var sourceFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var sourceFile = await sourceFolder.CreateFileAsync("database", 
    Windows.Storage.CreationCollisionOption.OpenIfExists);
var targetFolder = await sourceFolder.CreateFolderAsync("~", 
    Windows.Storage.CreationCollisionOption.OpenIfExists);
var targetFile = await targetFolder.CreateFileAsync(sourceFile.Name,
    Windows.Storage.CreationCollisionOption.ReplaceExisting);
await sourceFile.MoveAndReplaceAsync(targetFile);
这不仅是一个好主意,我有一种感觉,它将纠正你的问题。请记住,您始终可以查询并询问是否完成了一次转移(您是否没有完成两次转移)

祝你好运