Connecting to shared network resources doesn't always work


I am working with the code from this tutorial to access files remotely C# NetworkConnection for file share or other remote communication

I can connect to the remote directory and access the files which are just .jpg images.

This is the code for accessing the images:

public ActionResult GetPhoto(string cpuNr, Int64 imageNameNr)
    string source = @"ipadress\photos";
    string imgPath = Path.Combine(path where the image is from the cpuNr and imageNameNr build toghether);

    FileContentResult result = null;

    using(var share = new NetworkConnection(source, new NetworkCredentials())
        byte[] fileContent = System.IO.File.ReadAllBytes(imgPath);
        result = File(fileContent, "image/jpeg");

    return result;

This works fine in most of the cases. But sometimes I get an error:

Network Error: System.ComponentModel.Win32Exception (0x80004005):
Error connecting to remote share.

The source couldn't be accessed. It doesn't mean that a specific image can't be always accessed, because sometimes it does and sometimes it doesn't.

Is there any way around this error, any fix, because I can't find anything that will help me further for finding the reason of this problem or a solution for it.

EDIT The same file, from the same path, with the same user, sometimes gets accessed normally, but sometimes not.

asked on Stack Overflow Feb 11, 2020 by arianit ax • edited Feb 12, 2020 by arianit ax

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0