problem with the file upload dialog hi,
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.
love_dude1984
Junior Poster in Training
92 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2
Please post the relevant code so we can see where the wires are getting crossed.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
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);
FileUpload1.SaveAs(abspath);
string sql;
sql=string.format("insert into tablename (filename,filepath) values ('{0}','{1}')",FileUpload1.FileName,relpath);
.....
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
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..
love_dude1984
Junior Poster in Training
92 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2
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?
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
this is my code on browse button
try
{
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
love_dude1984
Junior Poster in Training
92 posts since Aug 2008
Reputation Points: 10
Solved Threads: 2
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);
.....
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241