gpt4 book ai didi

c# - 如何从 SkyDrive 下载文件到 IsolatedStorage?

转载 作者:行者123 更新时间:2023-11-30 15:33:11 24 4
gpt4 key购买 nike

我正在编写一个 WP8(XAML 和 C#)应用程序来从 SkyDrive 读取一个文本文件并将其保存到 IsolatedStorage 中。

好像是读取了文件,但是我得到的数据是文件的描述,而不是文件的内容。

网盘中的文件名为:“myFile1.txt”
文件内容为:“这是一个测试文件1”

我的代码如下:

private async void btnDownload_Click( object sender, System.Windows.RoutedEventArgs e )
{
string fileID = "file.17ff6330f5f26b89.17FF6330F5F26B89!1644";
string filename = "myDownloadFile1.txt";
var liveClient = new LiveConnectClient( LiveHelper.Session );

// Download the file
liveClient.BackgroundDownloadAsync( fileID, new Uri( "/shared/transfers/" + filename, UriKind.Relative ) );

// Read the file
var FileData = await LoadDataFile< string >( filename );
Debug.WriteLine( "FileData: " + (string)FileData );
}


public async Task<string> LoadDataFile<T>( string fileName )
{
// Get a reference to the Local Folder
string root = ApplicationData.Current.LocalFolder.Path;
var storageFolder = await StorageFolder.GetFolderFromPathAsync( root + @"\shared\transfers" );

bool IsFileExist = await StorageHelper.FileExistsAsync( fileName, storageFolder );
if ( IsFileExist == true )
{
StorageFile storageFile = await storageFolder.GetFileAsync( fileName );
if ( storageFile != null )
{
// Open it and read the contents
Stream readStream = await storageFile.OpenStreamForReadAsync();
using ( StreamReader reader = new StreamReader( readStream ) )
{
string _String = await reader.ReadToEndAsync();
reader.Close();
return _String;
}
}
else
{
return string.Empty;
}
}
return string.Empty;
}
}

我运行这段代码得到的数据是:

{
"id": "file.17ff6330f5f26b89.17FF6330F5F26B89!1644",
"from": {
"name": "Eitan Barazani",
"id": "17ff6330f5f26b89"
},
"name": "myFile1.txt",
"description": "",
"parent_id": "folder.17ff6330f5f26b89.17FF6330F5F26B89!1643",
"size": 23,
"upload_location": "https://apis.live.net/v5.0/file.17ff6330f5f26b89.17FF6330F5F26B89!1644/content/",
"comments_count": 0,
"comments_enabled": false,
"is_embeddable": true,
"source": "https://fculgq.bay.livefilestore.com/y2m0zkxi9kpb4orfYNSLSwst5Wy3Z7g6wDj7CM3B6wcOth9eA-gUflXeSCAAH_JWx2co72sgOTcGgvkwQGI3Gn5E1qXnRoKpVbsX_olRrB5gnCNIm8GrUrORco8_-je1cet/myFile1.txt?psid=1",
"link": "https://skydrive.live.com/redir.aspx?cid=17ff6330f5f26b89&page=view&resid=17FF6330F5F26B89!1644&parid=17FF6330F5F26B89!1643",
"type": "file",
"shared_with": {
"access": "Just me"
},
"created_time": "2013-07-15T16:29:10+0000",
"updated_time": "2013-07-15T16:29:10+0000"
}

我不确定为什么我没有在文件中获取数据。知道我做错了什么吗?

谢谢,

最佳答案

我认为你需要:

liveClient.BackgroundDownloadAsync( fileID+"/content", new Uri( "/shared/transfers/" + filename, UriKind.Relative ) );

即在 fileID 字符串之后,您需要添加 "/content" 以获取文件内容,而不是元数据。

关于c# - 如何从 SkyDrive 下载文件到 IsolatedStorage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17665441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com