public async System.Threading.Tasks.Task <ActionResult> Upload(HttpPostedFileBase[] files, string clientId) { SignalRMessage signalR = new SignalRMessage(); signalR.clientId = clientId; try { if (files.Length > 0 && files[0].FileName.Contains(".json")) { foreach (HttpPostedFileBase file in files) { try { BinaryReader b = new BinaryReader(file.InputStream); byte[] binData = b.ReadBytes(file.ContentLength); string result = Encoding.UTF8.GetString(binData); string response = await GraphHelper.AddIntuneConfig(result, clientId); signalR.sendMessage("Success " + response); } catch (Exception e) { signalR.sendMessage("Error: " + e.Message); } } } else if (files.Length > 0 && files[0].FileName.Contains(".zip")) { try { MemoryStream target = new MemoryStream(); files[0].InputStream.CopyTo(target); byte[] data = target.ToArray(); using (var zippedStream = new MemoryStream(data)) { using (var archive = new ZipArchive(zippedStream)) { foreach (var entry in archive.Entries) { try { if (entry != null) { if (entry.FullName.Contains("WindowsAutopilotDeploymentProfile") || entry.FullName.Contains("DeviceConfiguration") || entry.FullName.Contains("DeviceCompliancePolicy") || entry.FullName.Contains("DeviceManagementScript") || entry.FullName.Contains("ManagedAppPolicy")) { using (var unzippedEntryStream = entry.Open()) { using (var ms = new MemoryStream()) { unzippedEntryStream.CopyTo(ms); var unzippedArray = ms.ToArray(); string result = Encoding.UTF8.GetString(unzippedArray); if (!string.IsNullOrEmpty(result)) { string response = await GraphHelper.AddIntuneConfig(result, clientId); if (!(string.IsNullOrEmpty(response))) { signalR.sendMessage("Success " + response); } } } } } } } catch (Exception e) { signalR.sendMessage("Error: " + e.Message); } } } } } catch (Exception e) { signalR.sendMessage("Error: " + e.Message); } } else if (files.Length > 0) { signalR.sendMessage("Error unsupported file: " + files[0].FileName); } } catch (Exception e) { signalR.sendMessage("Error: " + e.Message); } signalR.sendMessage("Done#!"); return(new HttpStatusCodeResult(204)); }