1

我正在尝试覆盖文件的内容,但它不断抛出拒绝访问

System.IO.Stream s2 = await Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForWriteAsync("Assets\\xyz.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);
System.IO.StreamWriter sw = new StreamWriter(s2);

我怎样才能让它工作?例外是

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__10.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.IO.WindowsRuntimeStorageExtensions.<OpenStreamForWriteAsyncCore>d__10.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
  at
4

2 回答 2

3

从外观上看,您无法写入安装软件包的区域。从“应用程序包和部署”

Windows 应用商店应用部署

Windows 应用商店应用模型是一个声明性状态驱动的过程,它在单个包中提供应用的所有安装和更新数据和说明。在这种声明性模型中,部署操作是可靠的。包中的文件是不可变的,这意味着它们在交付到计算机后没有被修改过。因为包所有者不需要编写自定义操作和代码,所以减少了故障点的数量。

如果您需要为所有用户更新资产,听起来您应该只发布一个新版本,例如通过隔离存储 API。

如果您需要编写特定于用户的数据,则需要选择不同的位置。

于 2013-01-25T18:51:54.617 回答
0

您需要写入如下位置:ApplicationData.Current.TemporaryFolder

于 2014-11-17T21:33:46.453 回答