【问题标题】:Download and launch default app in windows phone 8 in C#在 C# 中在 windows phone 8 中下载并启动默认应用程序
【发布时间】:2012-12-16 20:05:24
【问题描述】:

我正在使用 Live api 下载 SkyDrive 文件。

我的代码有一个触发OnDownloadedCompleted函数的下载点击事件。

OnDownloadedCompleted 函数将文件复制到“文件名”。

并调用 DefaultLaunch(),它接受“文件名”并尝试通过 windows phone 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());

        }
    }

【问题讨论】:

  • "filename" 和 "File.one" 文件名如何相同?

标签: c# live windows-phone-8 onedrive


【解决方案1】:

试试这个教程..http://msdn.microsoft.com/en-us/live/ff519582.aspx..那里给出了如何在 Windows 8 平台上使用 live sdk

【讨论】:

  • 嘿,实际上我尝试使用测试数据并命名为 File.one。它的实际文件名。
  • zedray - 请您具体说明一下。感谢您的宝贵时间!
  • 嘿,我通过将“/content”放在文件 id 之后来实现代码。现在它正在工作,但是我无法打开“.onepkg”格式的文件。理想情况下,它们应该在 OneNote 中打开,但它要求我在商店中查找应用程序。任何建议/指针?感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多