CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2014
    Posts
    29

    get image based on textbox proplem

    Hi guys i have proplem I have image file jpg and his name 111.jpg found in another computer in domain in shared folder
    I need when i write in textbox 111 and click button get picture with name 111.jpg
    from shared folder in network and get it to local computeres work in domain
    how i get or making this by c# code

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: get image based on textbox proplem

    Browse for the File, if you have permission, it should show up.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2014
    Posts
    29

    Re: get image based on textbox proplem

    I can browse it without permission
    can you give me code that achieve this task

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: get image based on textbox proplem

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jan 2014
    Posts
    29

    Re: get image based on textbox proplem

    Quote Originally Posted by dglienna View Post
    Name:  proplem picture1.jpg
Views: 147
Size:  18.6 KB

  6. #6
    Join Date
    Jan 2014
    Posts
    29

    Re: get image based on textbox proplem

    the case what i need is above
    what i need is to when i write employee no in text box1
    and press button1 go to path in shared folder in server 192.168.1.10 and show image that found in shared folder have all permission 192.168.1.10/D:/images if found
    please help me in this task

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: get image based on textbox proplem

    Looks like you're file is in the F: drive
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: get image based on textbox proplem

    It's not clear what the problem is.

    Do you have code that displays the FolderBrowserDialog? If so..
    In the fb dialog can you navigate to the network drive? If so..
    Are you able to retrieve the full network path to the file? If so..
    Does the image display?

    Does any of this work with an image on a local drive?

    Please create a small test app, zip it up and post it here.

  9. #9
    Join Date
    Jan 2014
    Posts
    29

    Re: get image based on textbox proplem

    Quote Originally Posted by Arjay View Post
    It's not clear what the problem is.

    Do you have code that displays the FolderBrowserDialog? If so..
    In the fb dialog can you navigate to the network drive? If so..
    Are you able to retrieve the full network path to the file? If so..
    Does the image display?

    Does any of this work with an image on a local drive?

    Please create a small test app, zip it up and post it here.
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Drawing.Imaging;
    using System.IO;

    namespace FleetManagment
    {
    {
    FleetManagment.Fleet fleet2 = new FleetManagment.Fleet();
    private void button2_Click(object sender, EventArgs e)
    {
    try
    {
    string[] fileNames = Directory.GetFiles("D:\\Images");
    foreach (string file in fileNames)
    {

    if (file.Contains(textBox1.Text))
    {
    pictureBox1.Image = Image.FromFile(Path.Combine("D:\\Images", textBox1.Text) + ".jpg");
    }
    else
    {
    MessageBox.Show("File not exist");
    }
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString ());
    }

    }
    }
    }
    The code above is get picture from local machine and work successfully what i need is :
    1- get image from server 192.168.1.10 in folder path D:/images
    2-if folder images not have image written in textbox and press
    any file name wrong in textbox it give me exception
    how to prevent exception from show

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: get image based on textbox proplem

    Your logic is incorrect for loading the file as an image.

    Instead of using the textbox1.text value, use file.FullName

    if (file.Contains(textBox1.Text))
    {
    pictureBox1.Image = Image.FromFile(Path.Combine(file.FullName);
    }
    ...
    Actually, this whole logic is wrong because if there are more than one file in the folder, you will always get the "File not Exist" message box.

    If you need to capture an exception, use a try/catch block.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured