hi

im trying to upload a file with the help of fileupload control. im using following code to save the file in to the database

upPic.SaveAs(Server.MapPath("Images/") +
                     txtPrdId.Text.Trim() + ".jpg");//System.IO.Path.GetExtension(upPic.PostedFile.FileName));

the file gets saved perfectly..but when i try to display the same image somewher else, it shows a blank pic...

when i checked with the entry in the database it gets saves with my local machines path...for eg., c:/abc/Images/abc.jpg

when i enter a path Images/abc.jpg manually in the database it works fine...

what i can do to store the file in the same folders sub folder ie, Images folder?i dont want the c:/ n else path to be saved in the DB,

n when i try to save the file with following code

upPic.SaveAs(("Images/") +
                     txtPrdId.Text.Trim() + ".jpg");//System.IO.Path.GetExtension(upPic.PostedFile.FileName));

it gives me an error like a root directory needed to be defined.

What i can do? please help me..its urgent...

Thanks..

Recommended Answers

All 2 Replies

Store root relative into (daabase) table.

string dpath="~/Images/" + txtPrdId.Text.Trim() + ".jpg";

and use absolute path to save the uploaded file,

string ufile=MapPath("~/Images/" + txtPrdId.Text.Trim() + ".jpg");
 upPic.SaveAs(ufile);

Don't flag your question as “Urgent”.

Use the following code it works fine for me

ImageUrl='<%#Server.MapPath(@"~\uploadedImages\"+DataBinder.Eval(Container.DataItem, "SmallImg"))%>'

hi

im trying to upload a file with the help of fileupload control. im using following code to save the file in to the database

upPic.SaveAs(Server.MapPath("Images/") +
                     txtPrdId.Text.Trim() + ".jpg");//System.IO.Path.GetExtension(upPic.PostedFile.FileName));

the file gets saved perfectly..but when i try to display the same image somewher else, it shows a blank pic...

when i checked with the entry in the database it gets saves with my local machines path...for eg., c:/abc/Images/abc.jpg

when i enter a path Images/abc.jpg manually in the database it works fine...

what i can do to store the file in the same folders sub folder ie, Images folder?i dont want the c:/ n else path to be saved in the DB,

n when i try to save the file with following code

upPic.SaveAs(("Images/") +
                     txtPrdId.Text.Trim() + ".jpg");//System.IO.Path.GetExtension(upPic.PostedFile.FileName));

it gives me an error like a root directory needed to be defined.

What i can do? please help me..its urgent...

Thanks..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.