gog
gog

Reputation: 12988

Access to the path is denied in service fabric app

Im developing a service fabric Stateless Service App and at some point i need to download a file and save it to my desktop folder, but even if i run as Administrator i get the error:

Access to the path 'C:/Users/me/Desktop/filename' is denied

  using (var response = await _httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseHeadersRead))
  {
       using (var streamToReadFrom = await response.Content.ReadAsStreamAsync())
       {
          var fileName = $"C:\\Users\\me\\Desktop\\{name}{DateTime.Now.ToString("yyyyMMdd")}";
               using (var streamToWriteTo = File.Create(fileName))
               {
                    await streamToReadFrom.CopyToAsync(streamToWriteTo);
               }
       }
  }

Im testing runnning a local debug cluster but when i deploy it i want to save to a network path.

Upvotes: 2

Views: 2899

Answers (1)

zivkan
zivkan

Reputation: 15011

If you run Task Manager and go to the Details tab, you'll see that Service Fabric's processes (Fabric.exe, FabricGateway.exe, and others) are running as the NETWORK SERVICE user, not your own user account. The NETWORK SERVICE user doesn't have access to your user profile.

It's hard to suggest what you could do without knowing more about why you're trying to save files. But if that's something you're going to continue to do once your service makes it to production, I'd just implement your final solution now. I guess that's probably saving to Blob Storage, or maybe a database of some kind.

Upvotes: 3

Related Questions