public async Task <IActionResult> OnPost(List <IFormFile> files, string mockupName) { string targetDir = Path.Combine(MockupRoot, mockupName); if (files == null || files.Count < 0 || string.IsNullOrWhiteSpace(mockupName)) { return(Page()); } if (!IsValidFilename(mockupName)) { throw new ArgumentException("mockupName has invalid characters. only characters for a filename are allowed here.", nameof(mockupName)); } if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } var addedFiles = new List <string>(); foreach (var formFile in files) { if (formFile.Length > 0) { string filename = Path.GetFileName(formFile.FileName); if (!IsValidFilename(filename)) { throw new ArgumentException("File to upload contains invalid characters for a filename.", formFile.FileName); } var targetFilepath = Path.Combine(targetDir, filename); using (var stream = new FileStream(targetFilepath, FileMode.Create)) { await formFile.CopyToAsync(stream); } addedFiles.Add(targetFilepath); } } // for each .bmpr file convert to .json and put into targetDir var reader = new BmprReader(); foreach (var file in addedFiles) { var fi = new FileInfo(file); if (fi.Extension.Equals(".bmpr", StringComparison.OrdinalIgnoreCase)) { // copy to a temp file and then load from there sqlite dbs take time to release the file handle string tempBmprFilepath = Path.Combine(System.IO.Path.GetTempPath(), $"{System.IO.Path.GetRandomFileName()}.mockupweb.bmpr"); System.IO.File.Copy(file, tempBmprFilepath); var jsonFilename = $"{fi.Name}.json"; System.IO.File.WriteAllText( Path.Combine(targetDir, jsonFilename), reader.ReadFromFile(tempBmprFilepath).GetJson()); } } return(Redirect(@"/")); }
static void Main(string[] args) { string mockupfilepath = @"C:\temp\balsamiq\basic.bmpr"; var bmprfile = new BmprReader().ReadFromFile(mockupfilepath); //var ctrlsWithLinks = bmprfile.GetControlsWithLinks(); System.Console.WriteLine("foo"); }