I have created an MVC ASP.Net application and hosted in within IIS. Part of my app allows for users to upload a csv file. The data then needs to be read out of the csv and into an object to be used elsewhere.
The problem I have is when hosted in IIS the file can not be read. Here is my code:
using (StreamReader CsvReader = new StreamReader(filePath))
{
MessageHandler.NewNote("Opened CSV Reader");
string inputLine = "";
int lineNumber = 0;
while ((inputLine = CsvReader.ReadLine()) != null && !string.IsNullOrEmpty(inputLine))
{
//Do something here
}
}
Can someone please advise how I get this working. The filepath is generated using the following upload form:
<div id="UploadForm">
<% using (Html.BeginForm("FileUpload", "ImportExport", Model,
FormMethod.Post, new { enctype = "multipart/form-data" }))
{%>
<input name="uploadFile" type="file" accept=".csv" style="width:70%;" />
<input type="submit" value="Upload File" />
<%} %>
</div>