我正在尝试覆盖文件的内容,但它一直拒绝拒绝访问
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
答案 0 :(得分:3)
根据它的外观,您无法写入安装软件包的区域。来自"App packages and deployment":
Windows应用商店应用部署
Windows应用商店应用模型是一个声明式的状态驱动流程,可在单个包中提供应用的所有安装和更新数据及说明。在此声明性模型中,部署操作是可靠的。包中附带的文件是不可变的,这意味着它们自交付到计算机后未被修改。由于包所有者不需要编写自定义操作和代码,因此减少了失败点的数量。
如果您需要更新所有用户的资产,听起来您应该只发布一个新版本,例如通过隔离的存储API。
如果您需要编写特定于用户的数据,则需要选择其他位置。
答案 1 :(得分:0)
您需要写一个这样的位置: ApplicationData.Current.TemporaryFolder