M
M
masterOk2013-05-13 06:44:45
ASP.NET
masterOk, 2013-05-13 06:44:45

Asp.net MVC Upload file & save data?

how to save file to win azure blob and form data to SQL Azure on click on create button?
Separately, I can’t find how to do it together.
7TqpK.jpg
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
masterOk, 2013-05-14
@masterOk

here is the solution suggested to me
stackoverflow.com/questions/4784225/mvc-3-file-upload-and-model-binding

S
slrzz, 2013-05-14
@slrzz

I have not worked with Azure, but I think it will be something like this:

        [HttpPost]
        public ActionResult UploadForm(string ProductName, string Code, string Url)
        {
            var files = HttpContext.Request.Files;
            StreamReader stream = new StreamReader(files[0].InputStream);

            var fileToAdd = default(byte[]);
            using (var memstream = new MemoryStream())
            {
                stream.BaseStream.CopyTo(memstream);
                fileToAdd = memstream.ToArray();
            }

            // функция добавления записи в бд:
            AddData(ProductName, Code, Url, fileToAdd);

            
            return null;
        }

I
isxaker, 2013-11-01
@isxaker

The following code is working for me
Model

public class Book
{
     public string Title {get;set;}
     public string Author {get;set;}
}


controller
public class BookController : Controller
{
     [HttpPost]
     public ActionResult Create(Book model, IEnumerable<HttpPostedFileBase> fileUpload)
     {
         throw new NotImplementedException();
     }
}


and view
@using (Html.BeginForm("Create", "Book", FormMethod.Post, new { enctype = "multipart/form-data" }))
{      
     @Html.EditorFor(m => m)

     <input type="file" name="fileUpload[0]" /><br />      
     <input type="file" name="fileUpload[1]" /><br />      
     <input type="file" name="fileUpload[2]" /><br />      

     <input type="submit" name="Submit" id="SubmitMultiply" value="Upload" />
}


In order for the files to be transferred to the server, the name must
<input type="file" name="fileUpload[0]" />
match the name of the controller parameter
IEnumerable<HttpPostedFileBase> fileUpload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question