public bool UploadResource() { if (Request.Form.Files.Count < 1) { return(false); } var file = Request.Form.Files[0]; var resourceId = Request.Form["ResourceId"]; var resourceSet = Request.Form["ResourceSet"]; var localeId = Request.Form["LocaleId"]; if (string.IsNullOrEmpty(resourceId) || string.IsNullOrEmpty(resourceSet)) { throw new ApplicationException("Resourceset or ResourceId are not provided for upload."); } var item = Manager.GetResourceItem(resourceId, resourceSet, localeId); if (item == null) { item = new ResourceItem() { ResourceId = resourceId, ResourceSet = resourceSet, LocaleId = localeId, ValueType = (int)ValueTypes.Binary }; } using (var fs = file.OpenReadStream()) using (var ms = new MemoryStream()) { fs.CopyTo(ms); ms.Flush(); if (DbResourceDataManager.SetFileDataOnResourceItem(item, ms.ToArray(), file.FileName) == null) { return(false); } int res = Manager.UpdateOrAddResource(item); if (res < 0) { return(false); } } return(true); }