내 Windows 8.1 UA를 통해 .txt 파일에 쓰려고합니다.FileIO System.UnauthorizedAccessException 오류
var path = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile sampleFile = await path.GetFileAsync("info.txt");
await FileIO.WriteTextAsync(sampleFile, "new text");
을 그리고 난 때 WriteTextAsync
실행 System.UnauthorizedAccessException
오류가 점점 오전 : 내 C# 코드는 다음과 같습니다. 나는 나의 프로그램을 올리려고 시도했지만 여전히 같은 문제가있다.
.txt 파일이 어딘가에 열려있는 경우 모든 프로세스를 검사합니다.
파일이 읽기 전용이 아닙니다.
sampleFile.Path
C:\Users\myname\Documents\Visual Studio 2015\Projects\App2\App2\bin\Debug\AppX\info.txt
어떤 아이디어가 잘못된 여기에 무엇을 갈 수있는 유효한 경로를 반환? 이것이 초보자 질문이라면 미안합니다.
편집 : 추가 오류 메시지 Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll
스택 트레이스
Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.dll
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at App2.Data.SampleDataSource.<GetFreeSignal>d__11.MoveNext()
GetFreeSignal 기능
public static async Task<string> GetFreeSignal()
{
string sURL = await GetLastPage();
using (HttpClient clientduplicate = new HttpClient())
{
clientduplicate.DefaultRequestHeaders.Add("User-Agent",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
using (HttpResponseMessage responseduplicate = await clientduplicate.GetAsync(sURL))
using (HttpContent contentduplicate = responseduplicate.Content)
{
try
{
string resultduplicate = await contentduplicate.ReadAsStringAsync();
var websiteduplicate = new HtmlDocument();
websiteduplicate.LoadHtml(resultduplicate);
MatchCollection match = Regex.Matches(resultduplicate, "\\[B\\](.*?)<img", RegexOptions.Singleline);
var path = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile sampleFile = await path.GetFileAsync("info.txt");
await FileIO.WriteTextAsync(sampleFile, "new text");
return match[match.Count - 1].Groups[1].Value.TrimStart().Replace("'", "'").Replace("&", "&").Replace(""", "\"").Replace("’", "'").Replace("<br/>", "").Replace("<i>", "").Replace("</i>", "");
}
catch (Exception ex1)
{
Debug.WriteLine(ex1.StackTrace);
return string.Empty;
//throw ex1.InnerException;
}
}
}
}
작동하는지 – MethodMan
@MethodMan 이미 것을 시도 수동으로 응용 프로그램에서 실행할 때 대 후, 난 당신이 VS 닫고 제안하고 관리자로 다시 시작하고 볼 수있는 권한이 . 작동하지 않았 음 –
파일이 생성되지 않았기 때문일 수 있습니다. 프로그램을 실행하기 전에 파일을 만들 수 있습니다. – AxelWass