Пример #1
0
        public ActionResult Save(FormCollection form)
        {
            string       fileName       = "";
            ResultObject result_object  = new ResultObject();
            AboutUs      AboutUs_object = new AboutUs();

            foreach (string file in Request.Files)
            {
                var fileContent = Request.Files[file];
                if (fileContent != null && fileContent.ContentLength > 0)
                {
                    // get a stream
                    var stream = fileContent.InputStream;
                    // and optionally write the file to disk

                    var extension = Path.GetExtension(file);
                    fileName = Guid.NewGuid().ToString() + extension;//Path.GetFileName(file);
                    var path = Path.Combine(Server.MapPath("~/images"), fileName);
                    using (var fileStream = System.IO.File.Create(path))
                    {
                        stream.CopyTo(fileStream);
                    }
                }
            }
            AboutUs_object.Save(form, fileName, result_object);
            return(Json(result_object, JsonRequestBehavior.AllowGet));
        }