Results 1 to 3 of 3

Thread: Simple Problem... ("Filename Dialog" to a "String" (for Database Storage))

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    1

    Simple Problem... ("Filename Dialog" to a "String" (for Database Storage))

    Hey All;

    Of all the problems to encounter, so far everything works great in my Program, my Take on VB.net Control Arrays, and everything else, but here's my problem.

    I allow the user to Select an Image using an 'OpenFileDialog' (which I set the Form's Background with, no problem their). But to store it in my MySQL Database, I have to of course convert it to a STRING. But when I convert OpenFileDialog.Filename to a String, it removes special characters in the Path. See the Example of what it changes below:

    Example Path (User Selects):

    C:\Temp\BackGround.jpg

    After I do (ex. strImage = OpenFileDialog.FileName), with or without the .ToString after Filename, it stores the following Value in the String.

    C:TempBackGround.jpg (Removing the " \ " Characters)

    Obviously when I load this back from the Database later to Load that Image at that Path, it dosn't find it cause it's no longer a Proper Windows path without the " \ ".

    I've tried various common methods like doing a System.Convert.TOString(OpenFileDialog.FileName) etc., and they all leave the string without that character...

    Anyone have ideas or know a Method I'm missing to Convert this so the Path is Preserved properly so that I can recall this from the MySQL (uses a VarChar, no prob their), and set the Background to the Path with the Path stored PROPERLY???

    Thanks

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Simple Problem... ("Filename Dialog" to a "String" (for Database Storage))

    I'm not sure what you're running into, but I don't think it's the OpenFileDialog,
    for one thing, you already say that you're using the value in FileName to
    load the selected image as the form background, well that would fail if it was
    removing the "\" characters.

    Here's the example I tried without any problems:
    VB Code:
    1. Dim dialog As New OpenFileDialog
    2.       If dialog.ShowDialog() = DialogResult.OK Then
    3.          Dim strFile As String = dialog.FileName
    4.          TextBox1.Text = strfile
    5.       End If
    Perhaps you could post the code segment where the characters are being removed?
    My guess is there's another process being performed that's to blame.

    Regards,

    - Aaron.

  3. #3
    Addicted Member
    Join Date
    Aug 2001
    Posts
    152

    Re: Simple Problem... ("Filename Dialog" to a "String" (for Database Storage))

    I had the same problem I used the replace function to correct it
    May or may not be the correct way but it worked for me..

    example filename = replace(filename, "\", "\\", 1)

    works the same way with "'" "\'"
    filename = replace(filename, "'", "\'", 1)

    If this is not the correct way maybe someone else can correct it
    but it works for me just fine...
    My software never has bugs. It just develops random features.

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