Я заявил
Код: Выделить всё
using System;
using System.IO;
Код: Выделить всё
System.IO.File.Exists(Path.Combine(uploadPath, id)).
Невозможно использовать локальную переменную или локальную функцию «Система» объявлено в заявлении верхнего уровня в этом контексте
Есть ли какой-нибудь способ решить эту проблему?
Код: Выделить всё
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AutoMapper;
using System.Security.Claims;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Authorization;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
using RestSharp;
using Newtonsoft.Json.Linq;
namespace MyApp.API.Controllers
{
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class OrdersController : ControllerBase
{
...
[HttpPost("job/image/{id}")]
public async Task UploadFile(string id)
{
var files = Request.Form.Files;
var uploadPath = Path.Combine(env.WebRootPath, "assets/JobImages");
string[] strFile;
if (files.Count > 0)
{
try
{
if (!Directory.Exists(uploadPath))
Directory.CreateDirectory(uploadPath);
int i = 0;
strFile = new string[files.Count];
foreach (var file in files)
{
strFile[i] = id;
if (System.IO.File.Exists(Path.Combine(uploadPath, id)))
{
System.IO.File.Delete(Path.Combine(uploadPath, id));
}
using (var fileStream = new FileStream(Path.Combine(uploadPath, id), FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
i++;
}
}
catch (Exception ex)
{
Console.Write(ex);
return BadRequest();
}
}
else
{
return BadRequest("No file to upload");
}
return Ok(strFile);
}
}
}

Подробнее здесь: https://stackoverflow.com/questions/790 ... m-declared