I am trying to create a new jpeg file from an async task. The relevent code snippet is shown below
private async void OnSocketConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
await ReceiveFile(args);
}
private async Task ReceiveFile(StreamSocketListenerConnectionReceivedEventArgs args)
{
string pathString = @"C:\Users\sarav\test.jpg";
FileStream writeStream = new FileStream(pathString, FileMode.CreateNew, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true);
}
It throws the System.UnauthorizedAccessException above in FileStream. The same Filestream snippet for the same path is working on a console based C# application, in the sense the file test.jpg is getting created. Any suggestions as of what i am missing here.