im building an app where im tryin to upload an image to my database through file upload dialog box. my problem is, when i select a file thru the Fileupload dialog and save the path to a string variable n try to save it, the app takes the connectionstring as the path of the image.so it doesnt get saved in my database. i tried alot, bt when i select a file, the connectionstring gets changed.

what could be d possible reason for tht? im loadin the connection string on the same page n not in app.config file..

pl help me.

7 Years
Discussion Span
Last Post by __avd

This is C# forum. Ask web related question in ASP.NET forum.
You need to create relative path of uploaded file.

string relpath="~/images/" + FileUpload1.FileName;
 string abspath=MapPath("~/images/" + FileUpload1.FileName);
 string sql;
 sql=string.format("insert into tablename (filename,filepath) values ('{0}','{1}')",FileUpload1.FileName,relpath);

well..its a problem of C# only. we do have a file upload or say save file dialog box.

thanks for d code.i check and will let you knw if it works..


From the following text, i guess that you are working with web.

Fileupload dialog and save the path to a string variable n try to save it,

You have to use openFileDialog control. Isn't it?


this is my code on browse button

                picpathdialog.Filter = "BMP(*.bmp)|*.bmp|JPEG(*.jpeg,*.jpg,*.jpe,*.jfif)|*.jpg|GIF(*.gif)|*.gif|PNG(*.png)|*.png|All Picture Files(*.jpeg,*.jpg,*.gif,*.png,*.bmp)|(*.jpg,*.bmp,*.gif,*.jpeg)";
                if (picpathdialog.ShowDialog() == DialogResult.OK)
                        pictureBox1.ImageLocation = picpathdialog.FileName;
            catch (Exception error)
                MessageBox.Show("In open file dialog box" + error.Message);

n this is d code on upload button

pictureBox1.ImageLocation = txtpath.Text;

when i click on upload button, the connectionString gets replaced by the path of the image.

im also attachin the image to clarify the problem
please do let me knw where is d prob.

thank you..

Attachments pic_path.JPG 13.24 KB

Do not write such a code that could replace connectionstring Can I see the code of upload button?
Your code for upload button should be:

string relpath=picpathdialog.FileName;
 string sql;
 sql=string.format("insert into tablename (filepath) values ('{0}')",relpath);
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.