Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Display a image in picturebox

Display a image in picturebox

Scheduled Pinned Locked Moved XML / XSL
xmltutorial
7 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kpuneeth7
    wrote on last edited by
    #1

    i just want to load one image to the picturebox, who's path is stored in xml file. please tell me how to do this. GIve examples.

    S 1 Reply Last reply
    0
    • K kpuneeth7

      i just want to load one image to the picturebox, who's path is stored in xml file. please tell me how to do this. GIve examples.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      kpuneeth7 wrote:

      GIve examples

      Without knowing a little about the structure of your XML file and what technology you're using, that would be difficult to do... But it's simply a case of reading the XML file with an XML parser (think XmlReader in .NET), and finding the node containing the image file's path. The rest of it (displaying the image in the picture box) is nothing to do with XML.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

      K 1 Reply Last reply
      0
      • S Stuart Dootson

        kpuneeth7 wrote:

        GIve examples

        Without knowing a little about the structure of your XML file and what technology you're using, that would be difficult to do... But it's simply a case of reading the XML file with an XML parser (think XmlReader in .NET), and finding the node containing the image file's path. The rest of it (displaying the image in the picture box) is nothing to do with XML.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

        K Offline
        K Offline
        kpuneeth7
        wrote on last edited by
        #3

        I am using a simple xml file..... C:\Documents and Settings\Imran\Desktop\Picture\apple.jpg And i am using visual studio 2008 C# language. .net framework

        modified on Wednesday, February 24, 2010 3:20 AM

        S 1 Reply Last reply
        0
        • K kpuneeth7

          I am using a simple xml file..... C:\Documents and Settings\Imran\Desktop\Picture\apple.jpg And i am using visual studio 2008 C# language. .net framework

          modified on Wednesday, February 24, 2010 3:20 AM

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Here's a short C# program that will read the bit of XML you want and write it to the console.

          using System.Xml.XPath;
          using System.IO;

          namespace ConsoleApplication1
          {
          class Program
          {
          static void Main(string[] args)
          {
          // The XML file is specified as the first command line argument
          // imagePath will contain the image path contained in the XML file
          string imagePath = new XPathDocument(new StreamReader(args[0])).CreateNavigator().SelectSingleNode("/image/img").Value;
          System.Console.WriteLine(imagePath);
          }
          }
          }

          I've used XPath to navigate to the required element in the XML file (that's the .SelectSingleNode("/image/img") bit) and read the text there (the .Value bit). Simples.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

          K 1 Reply Last reply
          0
          • S Stuart Dootson

            Here's a short C# program that will read the bit of XML you want and write it to the console.

            using System.Xml.XPath;
            using System.IO;

            namespace ConsoleApplication1
            {
            class Program
            {
            static void Main(string[] args)
            {
            // The XML file is specified as the first command line argument
            // imagePath will contain the image path contained in the XML file
            string imagePath = new XPathDocument(new StreamReader(args[0])).CreateNavigator().SelectSingleNode("/image/img").Value;
            System.Console.WriteLine(imagePath);
            }
            }
            }

            I've used XPath to navigate to the required element in the XML file (that's the .SelectSingleNode("/image/img") bit) and read the text there (the .Value bit). Simples.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

            K Offline
            K Offline
            kpuneeth7
            wrote on last edited by
            #5

            Thanks for the code.... BUt its giving indexoutofrange exception...... HElp

            S 1 Reply Last reply
            0
            • K kpuneeth7

              Thanks for the code.... BUt its giving indexoutofrange exception...... HElp

              S Offline
              S Offline
              Stuart Dootson
              wrote on last edited by
              #6

              You need to give a command line argument that specifies the XML file...the code comments DO say that....

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

              K 1 Reply Last reply
              0
              • S Stuart Dootson

                You need to give a command line argument that specifies the XML file...the code comments DO say that....

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

                K Offline
                K Offline
                kpuneeth7
                wrote on last edited by
                #7

                Thanks dude.....:) I got it :) Thank u very much

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups