public string Upload() { var upload = Request.Form.Files["file"]; if (upload != null) { // получаем имя файла var fileName = Path.GetFileName(upload.FileName); using (var ms = new MemoryStream()) { upload.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); try { var dxfFile = DxfFile.Load(ms); var fileJson = new DxfToJsonConverter().EncodeFileJson(dxfFile); return(fileJson); } catch (Exception e) { return($"{{\"error\":\"{e.Message}\"}}"); } } } return("{\"error\":\"No File Uploaded\"}"); }
private void buttonOpenDxf_Click(object sender, EventArgs e) { var opf = new OpenFileDialog(); opf.Filter = "DXF Files(*.dxf)|*.dxf"; if (opf.ShowDialog() == DialogResult.OK) { dxfFile = DxfFile.Load(opf.FileName); Renderer.Render(dxfFile, bitmap, pictureBoxMain.Width, pictureBoxMain.Height); var encodedFile = new DxfToJsonConverter().EncodeFileJson(dxfFile); File.WriteAllText("json.json", encodedFile); pictureBoxMain.Refresh(); labelCost.Text = "Cost: " + new Mather().GetFileTotalLength(dxfFile) + " c.u."; } Focus(); }