Clever-1945
12/1/2017 - 5:01 AM

upload file #CSharp

upload file #CSharp

//Пример загрузки файла с клиента на сервер
//Attachment - это имя инпута файла
public ActionResult UploadMentalMap(bool? IsRootUpload , CheckTree Parent , HttpPostedFileBase Attachment)
{
    if(Parent == null)
        return Json(new { success = false, Message = "Не выбран родительский узел, в который следует делать выгрузку ментальной карты" }, JsonRequestBehavior.AllowGet);

    if (Attachment == null)
        return Json(new { success = false, Message = "Не передан файл на сервер" }, JsonRequestBehavior.AllowGet);

    if((Path.GetExtension(Attachment.FileName) ?? "").Trim().ToLower() != ".mm")
        return Json(new { success = false, Message = "Файл не является ментальной картой" }, JsonRequestBehavior.AllowGet);
    byte[] buffer = new byte[Attachment.ContentLength];
    Attachment.InputStream.Read(buffer, 0, buffer.Length);
    string content = Encoding.UTF8.GetString(buffer);
}