在Windows Phone上将文件上传到Skydrive

时间:2013-06-13 19:46:32

标签: c# windows-phone-7 onedrive

这适用于Windows Phone 7.1。目前这是我的代码。

private async void UploadFile(IsolatedStorageFile myFile)
{
    if ( App.ConnectClient != null )
    {
        App.ConnectClient.BackgroundUploadAsync("me/skydrive",
                                                          new Uri("/shared/transfers/" + testFileName, UriKind.Relative),
                                                          OverwriteOption.Overwrite);
    }
}

它运行时没有出错,但是当我检查skydrive时,文件不存在。

如果需要,这是我的文件创建代码

private IsolatedStorageFile WriteCSV()
{
    IsolatedStorageFile myStorage = IsolatedStorageFile.GetUserStoreForApplication();

    testFileName = "sample.csv";

    using ( StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream(testFileName, FileMode.Create, FileAccess.Write, myStorage)) )
    {
        writeFile.WriteLine("some data");
        writeFile.Close();
    }

    return myStorage;
}

1 个答案:

答案 0 :(得分:1)

创建文件时,它不是在/ shared / transfers位置创建的,而是在root中创建 - “/”

所以这应该更好:

if ( App.ConnectClient != null )
    {
        App.ConnectClient.GetCompleted += ConnectClient_GetCompleted;
        App.ConnectClient.BackgroundUploadAsync("me/skydrive",
                                                new Uri("/" + testFileName, UriKind.Relative),
                                                OverwriteOption.Overwrite);
    }