Link to home
Start Free TrialLog in
Avatar of njgroup
njgroup

asked on

why network path (or mapped driver path) is not working?

I have a picturebox object, I want to assign image to that picturebox, the problem that the image is located in my server, I got a driver mapped for images folder (Z: driver), so I was trying:

 
string imgPath = System.IO.Path.Combine("Z:\\",row.Cells["ImgPath"].Value.ToString());
picturebox.Image = System.Drawing.Image.FromFile(imgPath, true);

// this code is not working, null is returned from Image.FromFile method

Open in new window


but previous code is not working, null is returned from Image.FromFile method.

I tried the UNC path: \\192.168.1.161\d$\ProductManagmentSystem\images\175.png
but also that is not working

so any idea what to do?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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 njgroup
njgroup

ASKER

I got this exception:
Parameter is not valid.

this is the code:

                    string imgPath = System.IO.Path.Combine("\\\\192.168.1.161\\ProductManagmentSystem\\", row.Cells["ImgPath"].Value.ToString());

                    Bitmap b = new Bitmap(imgPath);

the actual value of ImgPath is: "\\192.168.1.20\ProductManagmentSystem\images\175.png"

so what to do?
Bitmap may not accept UNC paths, but Image.FromFile(imgPath, true) will. I did that kind of code before and some links confirm my construct:
http://www.webmasterworld.com/microsoft_asp_net/3956049.htm

Please replace:
picturebox.Image = System.Drawing.Image.FromFile(imgPath, true);
with:
if (File.Exists(imgPath))
  picturebox.Image = System.Drawing.Image.FromFile(imgPath, true);
Note: Please post .net , vs version.

Avatar of njgroup

ASKER

I got invalid path,
here is code snippet:

 
foreach (DataGridViewRow row in dgvProductsGridTMP.Rows)
                {
                    string imgPath = System.IO.Path.Combine("\\\\192.168.1.20\\ProductManagmentSystem\\", row.Cells["ImgPath"].Value.ToString());

                    if (System.IO.Directory.Exists(imgPath))
                    {
                        row.Cells["productImage"].Value = System.Drawing.Image.FromFile(imgPath);
                    }
                    else
                    {
                        MessageBox.Show("Invalid Path");
                    }
                }

Open in new window


its .net 3.5 2008
It is invalid path because you are using Directory.Exists, you have to use File.Exists
Avatar of njgroup

ASKER

yes, you are right, buy still I have same problem,

here is image snapshot:

 User generated image
Avatar of njgroup

ASKER

I tried it without File.Exists, I got exception not found:

 User generated image
but its there, I can see it in mapped driver, so there is access to the file!

 User generated image
foreach (DataGridViewRow row in dgvProductsGridTMP.Rows)
                {
                    string imgPathx = System.IO.Path.Combine("\\\\192.168.1.20\\ProductManagmentSystem\\", row.Cells["ImgPath"].Value.ToString());

                    if (System.IO.File.Exists(imgPathx))
                    {
                        row.Cells["productImage"].Value = System.Drawing.Image.FromFile(imgPathx);
                    }
                    else
                    {
                        MessageBox.Show("Invalid Path");
                    }
                }

//noticed that imgPath from row.cells did not change, but the variable imgPathx change.
if not workin, try to use computer name,  not ip address.
If you type in windows explorer:
\\192.168.1.20\ProductManagmentSystem\images\
- Can you see your file? Are you using the same user when you are running your application?
- Is this a desktop(winforms/wpf) or asp.net application or windows service? the solution posted above works for winform applications only. What kind of project does your posted code belong to?
Avatar of njgroup

ASKER

yes, it was ip problem, ... its working fine now