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. C#
  4. Empty path name is not legal

Empty path name is not legal

Scheduled Pinned Locked Moved C#
databasecom
11 Posts 4 Posters 0 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.
  • D Offline
    D Offline
    DPaul1994
    wrote on last edited by
    #1

    I want to insert an image in database. But if I don't choose any image, I receive : `Empty path name is not legal`. In database, `image` field is BLOB and is null. Where is my mistake cause I can't figure it out..I think that I should verify if textBox5 is null and if is, `imageBt=null`. I tried this but it didn't worked. This is the code that I'm using to insert the image:

    byte[] imageBt = null;
    FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
    BinaryReader br = new BinaryReader(fstream);
    imageBt = br.ReadBytes((int)fstream.Length);
    SQLiteCommand com = new SQLiteCommand("insert into questions(image) values(@IMG)", Conexiune.getConnection());
    com.Parameters.Add(new SQLiteParameter("@IMG", imageBt));
    com.ExecuteNonQuery();

    S P 2 Replies Last reply
    0
    • D DPaul1994

      I want to insert an image in database. But if I don't choose any image, I receive : `Empty path name is not legal`. In database, `image` field is BLOB and is null. Where is my mistake cause I can't figure it out..I think that I should verify if textBox5 is null and if is, `imageBt=null`. I tried this but it didn't worked. This is the code that I'm using to insert the image:

      byte[] imageBt = null;
      FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
      BinaryReader br = new BinaryReader(fstream);
      imageBt = br.ReadBytes((int)fstream.Length);
      SQLiteCommand com = new SQLiteCommand("insert into questions(image) values(@IMG)", Conexiune.getConnection());
      com.Parameters.Add(new SQLiteParameter("@IMG", imageBt));
      com.ExecuteNonQuery();

      S Offline
      S Offline
      Sascha Lefevre
      wrote on last edited by
      #2

      Try this instead of just checking for null:

      if (!String.IsNullOrWhiteSpace(textBox5.Text))
      {
      // open file etc.
      }

      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

      D 1 Reply Last reply
      0
      • D DPaul1994

        I want to insert an image in database. But if I don't choose any image, I receive : `Empty path name is not legal`. In database, `image` field is BLOB and is null. Where is my mistake cause I can't figure it out..I think that I should verify if textBox5 is null and if is, `imageBt=null`. I tried this but it didn't worked. This is the code that I'm using to insert the image:

        byte[] imageBt = null;
        FileStream fstream = new FileStream(this.textBox5.Text, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fstream);
        imageBt = br.ReadBytes((int)fstream.Length);
        SQLiteCommand com = new SQLiteCommand("insert into questions(image) values(@IMG)", Conexiune.getConnection());
        com.Parameters.Add(new SQLiteParameter("@IMG", imageBt));
        com.ExecuteNonQuery();

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        First of all, you should name your textboxes with a more meaningful name. Then, you really want to test some validity like this:

        if (string.IsNullOrWhitespace(textBox5.Text)) return;
        if (!File.Exists(textBox5.Text)) return;

        D 1 Reply Last reply
        0
        • S Sascha Lefevre

          Try this instead of just checking for null:

          if (!String.IsNullOrWhiteSpace(textBox5.Text))
          {
          // open file etc.
          }

          If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

          D Offline
          D Offline
          DPaul1994
          wrote on last edited by
          #4

          Where should I put this?..

          S 1 Reply Last reply
          0
          • P Pete OHanlon

            First of all, you should name your textboxes with a more meaningful name. Then, you really want to test some validity like this:

            if (string.IsNullOrWhitespace(textBox5.Text)) return;
            if (!File.Exists(textBox5.Text)) return;

            D Offline
            D Offline
            DPaul1994
            wrote on last edited by
            #5

            Where should I put this?..

            P 1 Reply Last reply
            0
            • D DPaul1994

              Where should I put this?..

              S Offline
              S Offline
              Sascha Lefevre
              wrote on last edited by
              #6

              "Around" your posted code. Or what Pete replied before your posted code (that if (!File.Exists(textBox5.Text)) that he posted also).

              If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

              D 1 Reply Last reply
              0
              • D DPaul1994

                Where should I put this?..

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Before the point that your code blows up would probably seem a sensible place don't you think?

                D 1 Reply Last reply
                0
                • P Pete OHanlon

                  Before the point that your code blows up would probably seem a sensible place don't you think?

                  D Offline
                  D Offline
                  DPaul1994
                  wrote on last edited by
                  #8

                  I managed to fix it. Gosh it was so easy..I think I'm tired :)) Sorry for this boring question. Thank you!

                  1 Reply Last reply
                  0
                  • S Sascha Lefevre

                    "Around" your posted code. Or what Pete replied before your posted code (that if (!File.Exists(textBox5.Text)) that he posted also).

                    If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                    D Offline
                    D Offline
                    DPaul1994
                    wrote on last edited by
                    #9

                    Gosh it was so easy..I think I'm tired :)) Sorry for this boring question. Thank you!

                    S D 2 Replies Last reply
                    0
                    • D DPaul1994

                      Gosh it was so easy..I think I'm tired :)) Sorry for this boring question. Thank you!

                      S Offline
                      S Offline
                      Sascha Lefevre
                      wrote on last edited by
                      #10

                      Hehe, alright :) To cover that topic in a general statement: Always check your inputs before trusting them.

                      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

                      1 Reply Last reply
                      0
                      • D DPaul1994

                        Gosh it was so easy..I think I'm tired :)) Sorry for this boring question. Thank you!

                        D Offline
                        D Offline
                        dhivya sakthi
                        wrote on last edited by
                        #11

                        :)

                        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