我使用直播API下載SkyDrive中文件。下載並啓動默認的應用程序在Windows 8手機
我的代碼有一個下載點擊事件觸發了OnDownloadedCompleted函數。
OnDownloadedCompleted函數將文件複製到「文件名」。
,並調用DefaultLaunch(),這需要在「文件名」,並試圖通過預設程序在Windows 8手機
啓動它,當我執行代碼(下載的文件是一個OneNote文件)OneNote將打開並顯示文件無法打開。
任何人都可以幫我驗證這段代碼嗎?
非常感謝!
private void btnDownload_Click(object sender, RoutedEventArgs e)
{
if (App.Current.LiveSession == null)
{
infoTextBlock.Text = "You must sign in first.";
}
else
{
LiveConnectClient client = new LiveConnectClient(App.Current.LiveSession);
client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompleted);
client.DownloadAsync("file_id");
}
}
爲OnDownloadCompleted的代碼是
void OnDownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
{
if (e.Result != null)
{
var filestream = File.Create(@"filename");
e.Result.Seek(0, SeekOrigin.Begin);
e.Result.CopyTo(filestream);
filestream.Close();
DefaultLaunch();
e.Result.Close();
}
else
{
infoTextBlock.Text = "Error downloading image: " + e.Error.ToString();
}
}
爲默認的啓動函數的代碼是
async void DefaultLaunch()
{
try
{
string imageFile = @"File.one";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);
var success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{}
else
{}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
Console.WriteLine(e.ToString());
}
}
如何' 「文件名」'和' 「File.one」'相同˚F ilename? –