Upload Multiple images to azure and retrieve using MVC

Posted by Mandlaa under ASP.NET MVC on 8/29/2013 | Points: 10 | Views : 3106 | Status : [Member] | Replies : 6
Upload Multiple images to azure and retrieve using MVC
This is my code for Uploading multiple images to azure,

This is my code,I am running this code Getting the following Error:

Error 2 foreach statement cannot operate on variables of type 'System.Web.HttpPostedFileBase' because 'System.Web.HttpPostedFileBase' does not contain a public definition for 'GetEnumerator' D:\DRIVE(D)\mindstick(Practice\NotousProducts\MvcWebRole1\Controllers\ProductsController.cs 64 21 MvcWebRole1

View:
@model MvcWebRole1.Models.Product

@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm("Create","Products",FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<fieldset>
<legend>Product</legend>

<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Image)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Image)*@
<input type="file" name="fileBase" id="filebase1" />
@Html.ValidationMessageFor(model => model.Image)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Image1)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Image1)*@
<input type="file" name="fileBase" id="filebase2" />
@Html.ValidationMessageFor(model => model.Image1)
</div>

<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

[HttpPost]
public ActionResult Create(Product p,HttpPostedFileBase fileBase)
{
if (fileBase.ContentLength > 0)
{
foreach (IEnumerable<HttpPostedFileBase> image in fileBase)
{
// Retrieve a reference to a container
CloudBlobContainer blobContainer = _myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob = blobContainer.GetBlobReference(fileBase.FileName);

// Create or overwrite the "myblob" blob with contents from a local file
blob.UploadFromStream(fileBase.InputStream);
}
}
}
//secode
CloudBlobContainer blobContainer1 =_myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob1 = blobContainer1.GetBlobReference(fileBase.FileName);

CloudBlobContainer blobContainer112 = _myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob112 = blobContainer112.GetBlobReference(fileBase.FileName);

List<string> blobs = new List<string>();
// Loop over blobs within the container and output the URI to each of them
foreach (var blobItem in blobContainer1.ListBlobs())
blobs.Add(blobItem.Uri.ToString());

// TODO: Add insert logic here
//Product p1 = new Product();
p.Image = blob1.Uri.ToString();
p.Image1 = blob112.Uri.ToString();
db.Products.InsertOnSubmit(p);
db.SubmitChanges();
return RedirectToAction("Index");

}




Responses

Posted by: Bandi on: 8/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link
http://stackoverflow.com/questions/7733381/file-upload-error-using-foreach-loop-does-not-contain-a-public-definition-f

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Mandlaa on: 8/29/2013 [Member] Starter | Points: 25

Up
0
Down
Thank you for replying,
Can you correct my code i am giving

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

Posted by: Bandi on: 8/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
--May be try this
Derive ProductsController.cs from IEnumerator and override the function GetEnumerator()....
Follow the below link
http://stackoverflow.com/questions/12096462/foreach-statement-cannot-operate-on-variables-of-type-dars-does-not-contain-a-pu?rq=1

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Bandi on: 8/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Check this....
http://stackoverflow.com/questions/14348451/using-html5-multiple-file-upload-with-asp-net

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Posted by: Mandlaa on: 8/29/2013 [Member] Starter | Points: 25

Up
0
Down
In My view Two different file upload controls
@model MvcWebRole1.Models.Product
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>

@using (Html.BeginForm("Create","Products",FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<fieldset>
<legend>Product</legend>

<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Image)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Image)*@
<input type="file" name="fileBase" id="filebase1" />
@Html.ValidationMessageFor(model => model.Image)
</div>

<div class="editor-label">
@Html.LabelFor(model => model.Image1)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Image1)*@
<input type="file" name="fileBase" id="filebase2" />
@Html.ValidationMessageFor(model => model.Image1)
</div>

<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}

<div>
@Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}


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

Posted by: Bandi on: 8/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
I haven't found the problem where that is causing...
I got one link to upload multiple files to Azure
http://www.dotnetcurry.com/ShowArticle.aspx?ID=891

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Login to post response