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:
but previous code is not working, null is returned from Image.FromFile method.
I tried the UNC path: \\192.168.1.161\d$\Product ManagmentS ystem\imag es\175.png
but also that is not working
so any idea what to do?
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
but previous code is not working, null is returned from Image.FromFile method.
I tried the UNC path: \\192.168.1.161\d$\Product
but also that is not working
so any idea what to do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.FromF ile(imgPat h, true);
with:
if (File.Exists(imgPath))
picturebox.Image = System.Drawing.Image.FromF ile(imgPat h, true);
Note: Please post .net , vs version.
http://www.webmasterworld.com/microsoft_asp_net/3956049.htm
Please replace:
picturebox.Image = System.Drawing.Image.FromF
with:
if (File.Exists(imgPath))
picturebox.Image = System.Drawing.Image.FromF
Note: Please post .net , vs version.
ASKER
I got invalid path,
here is code snippet:
its .net 3.5 2008
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");
}
}
its .net 3.5 2008
It is invalid path because you are using Directory.Exists, you have to use File.Exists
ASKER
foreach (DataGridViewRow row in dgvProductsGridTMP.Rows)
{
string imgPathx = System.IO.Path.Combine("\\ \\192.168. 1.20\\Prod uctManagme ntSystem\\ ", row.Cells["ImgPath"].Value .ToString( ));
if (System.IO.File.Exists(img Pathx))
{
row.Cells["productImage"]. Value = System.Drawing.Image.FromF ile(imgPat hx);
}
else
{
MessageBox.Show("Invalid Path");
}
}
//noticed that imgPath from row.cells did not change, but the variable imgPathx change.
{
string imgPathx = System.IO.Path.Combine("\\
if (System.IO.File.Exists(img
{
row.Cells["productImage"].
}
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\ProductMana gmentSyste m\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?
\\192.168.1.20\ProductMana
- 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?
ASKER
yes, it was ip problem, ... its working fine now
ASKER
Parameter is not valid.
this is the code:
string imgPath = System.IO.Path.Combine("\\
Bitmap b = new Bitmap(imgPath);
the actual value of ImgPath is: "\\192.168.1.20\ProductMan
so what to do?