Uploag images using images to azure and database?

Posted by Mandlaa under ASP.NET MVC on 1/29/2014 | Points: 10 | Views : 601 | Status : [Member] | Replies : 0
<div class="editor-label">
Select must 10 images***

</div>
<div class="editor-field">
<input type="file" id="MultipleFiles" name="MultipleFiles" multiple="multiple" />

</div>
CS Code:
 public ActionResult Create(HttpPostedFileBase[] MultipleFiles, FormCollection collection, demoproduct p)
{
try
{
// TODO: Add insert logic here

var Tagid = collection["TagNo"];
var qry = (from c in db.demoproducts 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);

}
}


//Retrive Images from blob

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();
p.ProductImage2 = blobs.ElementAt(2).ToString();
p.ProductImage3 = blobs.ElementAt(3).ToString();
p.ProductImage4 = blobs.ElementAt(4).ToString();
p.ProductImage5 = blobs.ElementAt(5).ToString();

db.demoproducts.InsertOnSubmit(p);
db.SubmitChanges();
return RedirectToAction("Index");

}
else
{
return RedirectToAction("EventCreationError");
}
}
catch
{
//return View();
return RedirectToAction("Create");
}
}

This is working fine for aploading AND save to database That image urls to database,
Supose i want to i want to select 2mages only at the time of saving to database not working




Responses

(No response found.)

Login to post response