Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
Hi friends,

I am try to save image path in mysql using C#,. I fetch the path in textbox3 and i add to mysql. the location has inserted. but correctly ,.

E:\mcsKIOSK\Image Files\Mcubic.png is correct. but the table it shows only E:mcsKIOSKImage FilesMcubic.png ,. If i try to access image whith this it gives error na.

Is any way to insert full path in mysql table?. i set varchar 100 for this.


Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.Filter = "All Image Files | *.*";
                if (dlg.ShowDialog() == true)
                {
                    image1.Source = new BitmapImage(new Uri(dlg.FileName, UriKind.Absolute));
                    string FileName = System.IO.Path.GetFileName(dlg.FileName);
                    string a = "E:\\jaga\\Files\\" + FileName;
                    string folderpath = "E:\\jaga\\Files\\";
                    System.IO.Directory.CreateDirectory(folderpath);
                    textBox3.Text = a;
                    if (!File.Exists(dlg.FileName))
                    {
                        MessageBox.Show("File Not Exit");
                    }
                    if (File.Exists(a))
                    {
                        MessageBox.Show("File Already Exit");
                    }
                    File.Copy(dlg.FileName, "E:\\jaga\\Files\\" + FileName);
                }


at last i try
string a = @"E:\jaga\Files\" + FileName;
way also,.

help me,.
Posted
Updated 23-Apr-18 23:55pm
v2

1 solution

You need to escape the backslash characters before inserting the path into the table.
 
Share this answer
 
v2
Comments
Sagotharan Jagadeeswaran 17-Feb-11 6:28am    
Thank u,.

I have got one idea inthis article,.
http://www.codeproject.com/KB/aspnet/ReplaceEscapeChar.aspx

folderpath = folderpath.Replace("\\", "''");

and

s = s.Replace("'","\\");

now its fine,. thank u.
Sebastian Boy 18-Jul-13 8:47am    
It's works very fine for me too. Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900