Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm new and need some help 2

Status
Not open for further replies.

numskull

Programmer
Dec 5, 2003
2
US
This is a question that may seem a little elementary to most of the seasoned developers here, but I'll risk embarassment anyways...

I'm trying to capture the data in a standard text box (usually a numeric part number..IE: '57231') and use it to search a specific location on a network server for an image with the same number. The trick is this: The number is always the same name as the image file which is always appended with a .JPG extension.

How in the world do I write the code to append the ".jpg" extension and point to the network share where the pics are so that the application can find the correct photo and display it in my picture box?

Any help is truly appreciated folks...

Respectfully,
Numskull

I thought I had a handle on this stuff yesterday...then along came today!
 
string str1 = "First string, ";
string str2 = "Second string";
string str3 = str1 + str2;
Console.WriteLine(str3);

This will output:
First string, Second string

So in your case, suppose the textbox were called txtBox1, maybe something like this:

string filename = txtBox1.Text + ".jpg";

That will give you the filename you're looking for. The rest should be fairly straight forward.
 
A better approach is to use the Path class from System.IO namespace. It will handle any backslashes, etc. that may be necessary.
Code:
string pathpart1 = "c:\\MyFiles";
string pathpart2 = txtBox1.Text;
string pathextension = ".jpg";

string fullpath = Path.Combine(Path.Combine(pathpart1,
                  pathpart2), pathextension);
I'm not sure, but I believe it will also work with a UNC path.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hey guys, I really, really appreciate the help. I was able to get this thing working yesterday before I ready either of these examples but it's amazing how many different ways there are to accomplish one task.

Again, THANKS!!!

Here is the snippet I used (a resident OOP programmer helped with this):

//create variable for Image file "ImgFile" which is pulled from the Part No. Field in the form.

string ImgFile = "";

if (txtVenCode.Text == "")
{
MessageBox.Show("You must enter a Vendor Code and Part Number to perform a search.");
}
else if (txtPartNo.Text == "")
{
MessageBox.Show("You must enter a Vendor Code and Part Number to perform a search.");
}
else
{
ImgFile = @"Y:\WebCatalog\images\parts\" + txtPartNo.Text+ ".jpg";
if (!System.IO.File.Exists(ImgFile))
{
MessageBox.Show("The file does not exist");
}
else
{
pbxPartImg.Image = Image.FromFile (ImgFile);
}
}



(Maybe, between the three examples, this will help someone else down the road with the same problem).



I thought I had a handle on this stuff yesterday...then along came today!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top