VB.NET如何绕过WinRT权限限制安全读取文件?
- 内容介绍
- 文章标签
- 相关推荐
本文共计505个文字,预计阅读时间需要3分钟。
我在尝试编写一些代码来写入文本文件。我有一个代码工作区,但今天(没有改动)它开始产生访问被拒绝错误。我使用的路径是LocalFolder(+Windows.Storage.ApplicationData.Current.LocalFolder)。我是否需要在清空?
我正在尝试编写一些代码来写入文本文件.我有代码工作…但今天(没有更改)它开始生成“访问被拒绝”错误.我写的是LocalFolder( Windows.Storage.ApplicationData.Current.LocalFolder).我是否必须在清单中声明我要在LocalStorage中保存文件?我知道我必须为我的文件,或者我错过了什么?这是我的示例方法,说明了我如何写出文件:
''' <summary> ''' Writes all of the text to the specified file in one of the specified safe storage folders. ''' </summary> ''' <param name="text">The text to write.</param> ''' <param name="append">Whether or not to append the data or overwrite what is in the file.</param> ''' <param name="fileName">The name of the file to write the data to.</param> ''' <param name="safeFolder">The safe storage folder that should be written to. These folders are isolated for the application to use ''' and do not require additional manifest permissions.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Async Function WriteAllText(text As String, append As Boolean, fileName As String, safeFolder As SafeStorageFolder) As Task Dim folder As Windows.Storage.StorageFolder Select Case safeFolder Case SafeStorageFolder.Local folder = Windows.Storage.ApplicationData.Current.LocalFolder Case SafeStorageFolder.Roaming folder = Windows.Storage.ApplicationData.Current.RoamingFolder Case SafeStorageFolder.Temp folder = Windows.Storage.ApplicationData.Current.TemporaryFolder Case Else folder = Windows.Storage.ApplicationData.Current.LocalFolder End Select Dim sf As StorageFile If append = True Then sf = Await folder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.OpenIfExists) Else sf = Await folder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting) End If ' WriteTextAsync will always overwrite the file even if the existing file has been opened. We'll use ' AppendTextAsync here, the above CreateFileAsync will handle whether the file has been truncated or not. Await FileIO.AppendTextAsync(sf, text) End Function 我在测试项目中使用了相同的代码逻辑,它对我来说很好.我没有通过所有追加/不追加路径,但我能够写入每个文件夹.
您是否从select中设置的文件夹对象中提取文件路径并仔细检查是否可以在文件资源管理器中打开它?
本文共计505个文字,预计阅读时间需要3分钟。
我在尝试编写一些代码来写入文本文件。我有一个代码工作区,但今天(没有改动)它开始产生访问被拒绝错误。我使用的路径是LocalFolder(+Windows.Storage.ApplicationData.Current.LocalFolder)。我是否需要在清空?
我正在尝试编写一些代码来写入文本文件.我有代码工作…但今天(没有更改)它开始生成“访问被拒绝”错误.我写的是LocalFolder( Windows.Storage.ApplicationData.Current.LocalFolder).我是否必须在清单中声明我要在LocalStorage中保存文件?我知道我必须为我的文件,或者我错过了什么?这是我的示例方法,说明了我如何写出文件:
''' <summary> ''' Writes all of the text to the specified file in one of the specified safe storage folders. ''' </summary> ''' <param name="text">The text to write.</param> ''' <param name="append">Whether or not to append the data or overwrite what is in the file.</param> ''' <param name="fileName">The name of the file to write the data to.</param> ''' <param name="safeFolder">The safe storage folder that should be written to. These folders are isolated for the application to use ''' and do not require additional manifest permissions.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Async Function WriteAllText(text As String, append As Boolean, fileName As String, safeFolder As SafeStorageFolder) As Task Dim folder As Windows.Storage.StorageFolder Select Case safeFolder Case SafeStorageFolder.Local folder = Windows.Storage.ApplicationData.Current.LocalFolder Case SafeStorageFolder.Roaming folder = Windows.Storage.ApplicationData.Current.RoamingFolder Case SafeStorageFolder.Temp folder = Windows.Storage.ApplicationData.Current.TemporaryFolder Case Else folder = Windows.Storage.ApplicationData.Current.LocalFolder End Select Dim sf As StorageFile If append = True Then sf = Await folder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.OpenIfExists) Else sf = Await folder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting) End If ' WriteTextAsync will always overwrite the file even if the existing file has been opened. We'll use ' AppendTextAsync here, the above CreateFileAsync will handle whether the file has been truncated or not. Await FileIO.AppendTextAsync(sf, text) End Function 我在测试项目中使用了相同的代码逻辑,它对我来说很好.我没有通过所有追加/不追加路径,但我能够写入每个文件夹.
您是否从select中设置的文件夹对象中提取文件路径并仔细检查是否可以在文件资源管理器中打开它?

