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?
njgroupAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
Mapped drive does not work, try:
imgPath = "\\SERVERNAME\ShareName\images\175.png"; // do not use d$
It should work. (just replace  SERVERNAME and ShareName and make sure you can access it from your computer)
Assumption: this code will work on desktop app, For asp.net you need to five your asp.net account access to folder or map your network folder as IIS folder.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
njgroupAuthor Commented:
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?
0
Miguel OzSoftware EngineerCommented:
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.

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

njgroupAuthor Commented:
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
0
Miguel OzSoftware EngineerCommented:
It is invalid path because you are using Directory.Exists, you have to use File.Exists
0
njgroupAuthor Commented:
yes, you are right, buy still I have same problem,

here is image snapshot:

 error
0
njgroupAuthor Commented:
I tried it without File.Exists, I got exception not found:

 not found error
but its there, I can see it in mapped driver, so there is access to the file!

 file is there
0
systanCommented:
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.
0
systanCommented:
if not workin, try to use computer name,  not ip address.
0
Miguel OzSoftware EngineerCommented:
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?
0
njgroupAuthor Commented:
yes, it was ip problem, ... its working fine now
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.