How to check Image url in database or not in MVC4

Posted by Mandlaa under ASP.NET MVC on 12/10/2013 | Points: 10 | Views : 1974 | Status : [Member] | Replies : 5
public ActionResult Createnewcar(FormCollection collection, ProductsHondaofConyers2 p, HttpPostedFileBase[] MultipleFiles,TagTable tb)
{
try
{
// TODO: Add insert logic here

var Tagid = collection["TagNo"];

var qry = (from c in db.ProductsHondaofConyers2s where c.TagNo ==Tagid select c).Count();


if (qry != 1)
{
foreach (var fileBase in MultipleFiles)
{
if (fileBase.ContentLength > 0)
{
Microsoft.WindowsAzure.StorageClient.CloudBlobContainer blobContainer = _myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob = blobContainer.GetBlobReference(fileBase.FileName);
blob.UploadFromStream(fileBase.InputStream);
}
}


List<string> blobs = new List<string>();

foreach (var fileBase in MultipleFiles)
{
Microsoft.WindowsAzure.StorageClient.CloudBlobContainer blobContainer1 = _myBlobStorageService.GetCloudBlobContainer();

CloudBlob blob1 = blobContainer1.GetBlobReference(fileBase.FileName);

blobs.Add(blob1.Uri.ToString());
}

p.ProductImage = blobs.ElementAt(0).ToString();
p.ProductImage1 = blobs.ElementAt(1).ToString();
}
else
{
return RedirectToAction("EventCreationError");
}
}
catch
{
//return View();
return RedirectToAction("Createnewcar");
}
}
This is my code

It's working perfectly

I want to add one more condition in this code what is that one is

Inserted first time images inseted successfully,

At the time of 2nd time ,Suppose can i try to insert same name image display errormessage

How can i do this one plz help me




Responses

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Check below URLs:-
http://www.codeproject.com/Questions/577090/hotplustoplusdisplayplusplusimageplusfrompluspathp
http://tech.pro/q/21/how-to-display-live-images-using-aspnet-mvc-with-database

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also refer:-
http://stackoverflow.com/questions/12088565/mvc4-project-images-not-displaying

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
I am inserting image Stored in database this like this url :http://tlick.blob.core.windows.net/images/Image1.jpg
2nd time inserting same image name Image1 disply error message like this image already exist

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/10/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
So,is it requirement that you have to insert same image again and again? if yes. then take Guid field,and based on guid,insert images.

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 12/10/2013 [Member] Starter | Points: 25

Up
0
Down
give me example for this requirement

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response