简体   繁体   English

如何从应用程序访问“我的用户”文件夹中的文件?

[英]How can I access files inside My User folder from the application?

I am creating an Windows Explorer kind of app using metro UI. 我正在使用Metro UI创建Windows Explorer类的应用程序。 I want to show content of a certain folder in my User folder. 我想在用户文件夹中显示某个文件夹的内容。

I wanted to know if it is possible to access the folders and files inside users folder and how do I do it? 我想知道是否可以访问用户文件夹中的文件夹和文件,我该怎么做?

Edit : 编辑:

I tried using StorageFolder. 我尝试使用StorageFolder。 For documents folder, it gives me an exception. 对于文件文件夹,它给了我一个例外。 在此处输入图片说明

您可以像这样访问users文件夹的内容:

string path = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)).ToString();

The KnownFolders.DocumentsLibrary folder has restrictions on its use. KnownFolders.DocumentsLibrary文件夹对其使用有限制。 You have to manually declare the capability in your manifest, declare specific file types you want to access, and then to publish the app in the Store you have to be using a company account (not an individual account), and have to submit written justification for your programmatic use of the folder. 您必须在清单中手动声明功能,声明要访问的特定文件类型,然后在商店中发布应用程序,您必须使用公司帐户(而不是个人帐户),并且必须提交书面证明供您以编程方式使用该文件夹。

See http://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx as well as the note for section 6.6 of http://msdn.microsoft.com/en-us/library/windows/apps/hh921583.aspx . 请参阅http://msdn.microsoft.com/zh-CN/library/windows/apps/hh464936.aspx以及http://msdn.microsoft.com/zh-CN/library/windows的 6.6部分的注释/apps/hh921583.aspx

Note that this is for programmatic access without user consent. 请注意,这是未经用户同意的程序访问。 If you use the file picker, the user can of course point to the documents folder thereby giving you permission to use it. 如果您使用文件选择器,则用户当然可以指向documents文件夹,从而授予您使用它的权限。 But without that, you need to use your app data folders where you do have programmatic access. 但是如果没有这些,则需要使用您具有程序访问权限的应用程序数据文件夹。

The underlying reasoning here is that files that your app it generating for its own use, that don't have direct meaning to the user, should go in app data to avoid polluting a folder like Documents with stuff that the user doesn't know what to do with. 这里的根本原因是,应用程序生成供用户自己使用的,对用户没有直接意义的文件应进入应用程序数据,以避免使用用户不知道的东西污染文件夹(如Documents)做。 For "user data" files--which the user does understand, you should give them the option to choose where those files go, hence the use of the file picker. 对于用户确实理解的“用户数据”文件,您应该给他们提供选择来选择这些文件的位置,从而使用文件选择器。

A few file types like music, pictures, and video have direct library access via manifest capabilities, but in that case the user generally understands that they're working with that kind of data. 诸如音乐,图片和视频之类的一些文件类型可通过清单功能直接访问库,但在那种情况下,用户通常会理解他们正在使用此类数据。

使用SpecialFolder来获取用户文件夹,并使用Directory.Enumerate()来获取文件夹中的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 .NET 6 从我的 controller 访问文件夹目录? - How can I access a folder directory from my controller with .NET 6? 如何从应用程序中注销用户? - How can I unregister my user from my application? 如何访问 WPF 项目中的本地文件夹以加载和存储文件? - How can I access a local folder inside a WPF project to load and store files? 如何将文件放入安装项目中用户的本地应用程序数据文件夹中? - How can I put files in the user's local application data folder in a setup project? 如何将文件保存在临时文件夹中? - How can I save files inside a temporary folder? 如何在WPF应用程序的用户控件中放置Win32浮动窗口? - How can I position a Win32 floating window inside a user control in my WPF application? 如何访问UWP中的当前应用程序文件夹? - How can I access the current application folder in UWP? 如何将文件夹从Windows资源管理器拖到ListView并将文件加载到其中? - How can I drag a folder from my Windows Explorer into a ListView and load the files into it? 如何从c#应用程序访问另一个应用程序上的菜单栏和子菜单? - How I can access to menubar and sub ment on another application from my c# application? 如何在资源文件夹中使用json? - How can I use json inside my resources folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM