【问题标题】:Is it possible to upload image or file to SkyDrive fom Metro Style App?是否可以通过 Metro Style App 将图像或文件上传到 SkyDrive?
【发布时间】:2012-10-04 06:01:43
【问题描述】:

是否可以通过 Metro Style App 将图像或文件上传到 SkyDrive?
我已经找到了如何从 SkyDrive 浏览文件。但我还没有找到关于将文件上传到 SkyDrive 的信息。如果您回复我,将非常感谢..

【问题讨论】:

  • 您使用的是 XAML 还是 HTML5?如果是 XAML,是 C# 还是 C++?

标签: image file upload microsoft-metro onedrive


【解决方案1】:

除非用户安装了桌面应用程序,否则我认为文件选择器方法不起作用。

您应该使用共享合同。如果您添加要共享的数据文件(存储项),则 SkyDrive 将被列为共享目标,并且用户会获得一个 UI,他们可以在其中选择要在 SkyDrive 中保存的位置。这就是我在我的应用中实现它的方式。

更多信息...

http://msdn.microsoft.com/en-us/library/windows/apps/hh771179.aspx

【讨论】:

  • 感谢 RobDurfee。看起来它只支持 javascript 和 html5。我正在为 XAML/C# 开发。
【解决方案2】:

您可以使用 FileSavePicker 来保存文件。这当然会让用户有机会选择他想要保存到本地文档文件夹或天空驱动器的位置。用户处于控制之中。

        FileSavePicker savePicker = new FileSavePicker();
        savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
        savePicker.DefaultFileExtension = ".YourExtension";
        savePicker.SuggestedFileName = "SampleFileName";
        savePicker.FileTypeChoices[".YourExtension"] = new List<string>() { ".YourExtension"};

        StorageFile file = await savePicker.PickSaveFileAsync();
        if (file != null)
        {
            await FileIO.WriteTextAsync(file, "A bunch of text to save to the file");
        }

请注意,在示例代码中,我正在代码中创建文件的内容。如果您希望用户从计算机中选择现有文件,那么您必须首先使用 FileOpenPicker,获取文件,然后使用 FileSavePicker 将所选文件的内容保存到 SkyDrive

【讨论】:

    【解决方案3】:

    假设您使用的是 XAML/JavaScript,建议的解决方案是使用 FilePicker。

    以下链接可能对您有所帮助。

    http://msdn.microsoft.com/en-us/library/windows/apps/jj150595.aspx

    【讨论】:

      【解决方案4】:

      感谢 Mamta Dalal 和 Dangling Neuron,但有问题。但看起来我不能使用 FileSavePicker。我必须上传文件(文档、照片)而不仅仅是文本文件。我必须从一条路径复制到另一条路径。如果我使用 FileSavePicker,我必须编写每个文件内容(文本、png、pdf 等)并且无法复制。目前我正在使用 FolderPicker。但不幸的是,FolderPicker 不支持 SkyDrive。我的代码如下:

      >FolderPicker saveFolder = new FolderPicker();
      >saveFolder.ViewMode = PickerViewMode.Thumbnail;
      >saveFolder.SuggestedStartLocation = PickerLocationId.Desktop;                
      >saveFolder.FileTypeFilter.Add("*");
      >StorageFolder storagefolderSave = await saveFolder.PickSingleFolderAsync();
      >StorageFile storagefileSave = [Selected storagefile with file picker];
      >await storagefileSave.CopyAsync(storagefolderSave,storagefileSave.Name,NameCollisionOption.ReplaceExisting);
      

      如果 FolderPicker 支持 SkyDrive 或者可以使用 FileSavePicker 复制文件,那就太好了。

      【讨论】:

      • 大家好,我已经找到了保存任何类型文件(文档、照片)的方法。它甚至适用于 SkyDrive。我将使用 FileSavePicker。谢谢你所做的一切。
      猜你喜欢
      • 2010-10-28
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      相关资源
      最近更新 更多