Привет. Я пытаюсь прочитать 2 txt-файла из веб-службы asmx, причина в том, что в файле 1 есть случайные буквы, из которых я должен найти подходящие слова из файла 2. Но я не знаю, как это сделать.прочитайте файлы.
это веб-сервис. Так я и делаю.Идея состоит в том, чтобы прочитать первый файл и получить маршруты для других, которые вы прочитали, и добавить их в список, но если у вас есть другая идея, я был бы признателен, если бы поделился
namespace NewShoreApp
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService : System.Web.Services.WebService
{
[WebMethod]
public string ReadData()
{
string[] lines = File.ReadAllLines(@"C:\Users\thoma\source\repos\NewShoreApp\NewShoreApp\Data\CONTENIDO.txt");
List<string> list = new List<string>();
foreach (var line in lines)
{
string data= File.ReadAllLines(line); //'Cannot implicitly convert type string[] to string'
list.AddRange(data); //Cannot convert from string to system.collections.generic IEnumerable<string>
}
return ".";
}
}
}
, это контроллер, на котором язагрузить файлы и добавить их в массив.
namespace NewShoreApp.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase[] files)
{
if (ModelState.IsValid)
{
try
{
foreach (HttpPostedFileBase file in files)
{
if (file != null)
{
var ServerPath = Path.Combine(Server.MapPath("~/Data"), Path.GetFileName(file.FileName));
file.SaveAs(ServerPath);
}
}
ViewBag.FileStatus = "File uploaded successfully.";
}
catch (Exception)
{
ViewBag.FileStatus = "Error while file uploading.";
}
}
return View("Index");
}
}
}
это модель
namespace NewShoreApp.Models
{
public class Data
{
//
[DataType(DataType.Upload)]
[Display(Name = "Upload File")]
[Required(ErrorMessage = "Please choose file to upload.")]
public HttpPostedFileBase[] files { get; set; }
}
}