0

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..

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Sals
0

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”.

0

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..

This question has already been answered. 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.