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
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:
Dim dialog As New OpenFileDialog
If dialog.ShowDialog() = DialogResult.OK Then
Dim strFile As String = dialog.FileName
TextBox1.Text = strfile
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.
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...