Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey i use linq to sql for store and retrive image from database ,i use varchar(max) datatype for it.
Here is my code for save image,

C#
EventBL r = new EventBL();
 r.Banner_SignUp_Page = System.IO.Path.GetFullPath(fuBanner.FileName);
 r.Insert();


and here is for retrive it.

C#
var result1 = from a in db.EMR_INVITATIONs
 join b in db.EMR_EVENTs on a.EventID equals b.EventID
 where b.EventID == (int)Session["eventid"]


 select new
 {
 Banner = b.Banner_SignUp_Page,
 };

 var ev = result1.First();

 Image1.ImageUrl = ev.Banner;



but in database i found that whole path of image isn't store .
in database some of the path is stored,and i can't retrive image from database
If there is solution or improvement in my code
Then please let me know,
Thanks in advaance.
Posted
Updated 13-Dec-13 0:09am
v3
Comments
Mike Meinz 13-Dec-13 6:49am    
Have you used the Visual Studio debugger to determine exactly what is returned by
System.IO.Path.GetFullPath(fuBanner.FileName);
or by
HttpContext.Current.Server.MapPath(fuBanner.FileName);?

Do that and the use the Improve Question link above to let us know.
Manfred Rudolf Bihy 13-Dec-13 6:59am    
Good advice! :)
ketan italiya 13-Dec-13 7:02am    
ok i try with this..
ketan italiya 13-Dec-13 8:06am    
no i use this method but i get wrong and empty path.
actually when i debug my code i found true path in r.insert(); method butin database i found wrong path.

You'd have to let us know what exactly the content of fuBanner.FileName is.
Is it a fully specified file path to an image on your disk?
Is it may be a relative URL?

In the former case you'd have to check what System.IO.Path.GetFullPath(fuBanner.FileName) returns.
In the latter case you'd need to find out the file's path in the filesystem:

C#
mappedPath = HttpContext.Current.Server.MapPath(fuBanner.FileName);


Regards,
— Manfred
 
Share this answer
 
v2
Comments
ketan italiya 13-Dec-13 6:39am    
thanks for reply,
but it is used for retrieve URL.
tell me if need changes in it.
You should call db.submitchanges() event after this code block

C#
EventBL r = new EventBL();
 r.Banner_SignUp_Page = System.IO.Path.GetFullPath(fuBanner.FileName);
 r.Insert();
db.submitchanges();
 
Share this answer
 
v3
Comments
ketan italiya 13-Dec-13 6:25am    
hey,no change ,i try with this,
still not saved full path.
not need to do it just make folder in your application to save image and get full image from there
and full path is also there
 
Share this answer
 
hi, first of all plz check the the column data type of db tabl in which u r storing the path, and then i suggest u to use .......
string filename = Server.MapPath(fuBanner.FileName);

then within insert code block ,u can save the path stored in filename variable.
try it out...
 
Share this answer
 

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