Pathname to be put into table has single quote as part of name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeafSmith
    New Member
    • Aug 2015
    • 6

    #1

    Pathname to be put into table has single quote as part of name

    Part of a table I have requires the pathname to a photostat of the check to placed into a field.

    Example, c:/foldera/folderb/The Hitchhiker's Guide to the Galaxy.png

    Well the ' in the name gives me fits. Error 42703.. I tried putting the string in quotes, "\"", but still a no-go.

    Any ideas?

    Thanks.
  • DeafSmith
    New Member
    • Aug 2015
    • 6

    #2
    Ok, figured it out. Apostrophe is the answer.
    That is double apostrophe.This will do it.

    Code:
    string xfile_path = "c:/foldera/folderb/The Hitchhiker's Guide to the Galaxy.png"
    string x = "\'";                   // what we want replaced
    if (xfile_path.ToString().IndexOfAny(new char[] { '\'' }) > -1)    
        {
          //* so we fix it
          string tests = xfile_path.ToString();
          tests = tests.Replace(x.ToString(), "\'\'");  //  <--- the answer. two single quotes (apostrophe)!
          xfile_path = tests.ToString();             // put the toothpaste back into the tube
          }
    
    //now the xfile_path has "c:/foldera/folderb/The Hitchhiker''s Guide to the Galaxy.png
    
    //And SQL will take that as being "c:/foldera/folderb/The Hitchhiker's Guide to the Galaxy.png"!
    Last edited by Rabbit; Sep 4 '15, 09:48 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

    Comment

    • TamarSolutions
      New Member
      • Sep 2015
      • 2

      #3
      You should never use special characters as a file path. That includes spaces ( although they are allowed it's best to stay away from all special characters and stick with numbers and letters.

      Comment

      Working...