Link to home
Start Free TrialLog in
Avatar of jetbet
jetbetFlag for New Zealand

asked on

C# Get image from Network Drive

I am trying to load an image located on a shared folder, on a mapped drive, into a picture box.
File.Exists always returns false even when the file exists.
Can anyone tell me why? I have given everyone Full access to the share.

private void AssignRunnersToPictureBoxes(EventDetails race)
        {
            String filePath = "I:\\";
            if (race != null)
            {
                for (int i = 1; i < 25; i++)
                {
                    PictureBox box = GetPictureBox(i);
                    if (box != null)
                    {
                        RunnerDetail runner = race.runners.GetRunner(i);
                        if (runner == null)
                        {
                            box.Tag = null;
                            box.Hide();
                        }
                        else
                        {
                            box.Tag = runner;
                       //     box.BackColor = Color.Green;
                          //  String silksFile = Path.Combine(filePath, "USA_Raci_3FBA615C103B385F0A7732B2D71BD1C8.png.bmp");
                            String silksFile = Path.Combine(filePath, runner.silkFileName + ".bmp");

                            if (File.Exists(@Path.Combine(filePath, runner.silkFileName + ".bmp")))
                            {
                                box.Image = Image.FromFile(silksFile);
                            }
                            
                            box.Show();

                        }
                    }
                }
            }

        }

Open in new window

Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

String silksFile = Path.Combine(filePath, runner.silkFileName + ".bmp"); // add entension here only
if (File.Exists(@Path.Combine(filePath, runner.silkFileName + ".bmp")))  // or add the extension here only otherwise it is doubled  i..e filename.bmp.bmp

you seem to have a preoccupation with adding + ".bmp" everywhere!

String silksFile = Path.Combine(filePath, "USA_Raci_3FBA615C103B385F0A7732B2D71BD1C8.png.bmp");

// inconsistent filename string name -- silksfile AND silkFileName
Avatar of jetbet

ASKER

The file is a converted png that has the .bmp added so it is  blahblahblah.png.bmp

The name stored in the object (runner) does not have this extra extention added on.

SilksFile is a local String variable silkFileName is a property on the object.

I am unsure of the solution you are proposing
Avatar of BakuRetsu_X
BakuRetsu_X

Print debug the full path after it has been combined.

String silksFile = Path.Combine(filePath, runner.silkFileName + ".bmp");

What does silksFile look like?
Avatar of jetbet

ASKER

The path is correct. I have checked this carefully in the debugger.
ASKER CERTIFIED SOLUTION
Avatar of d_york
d_york

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jetbet

ASKER

Thanks for the detailed response.

I will check out your ideas as soon as I can but am in the middle of a different project at the moment.