FileUpload was working. Then, I added a File.Delete statement to remove the file before uploading a new one. Since then, it will not upload a file although I have removed the File.Delete statement. This is the error message:
Could not find file 'C:\Users\richnval\Documents\My Web Sites\SIR34Golf\App_Data\Index list.csv'. on the line containing this statement:userData= File.ReadAllLines(dataFile);
The error is correct, there is no Index list.csv in App_Data.
Here is my code and yes, the "File uploaded" line does get displayed:
@usingSystem.IO;@{Layout="~/_SiteLayout.cshtml";Page.Title="NCGA Index list Upload";varfileName="";varfileMime="";vardataFile=Server.MapPath("~/App_Data/Index list.csv");ArrayuserData=null;char[]delimiterChar={','};intnr=1;intni=0;if(IsPost){varuploadedFile=Request.Files[0];fileName=Path.GetFileName(uploadedFile.FileName);userData=File.ReadAllLines(dataFile);foreach(stringdataLineinuserData){nr++;if(nr>5){foreach(stringdataItemindataLine.Split(delimiterChar)){<p>@dataItem</p>;}}}}}<!DOCTYPEhtml><html><head><title>NCGA Index list Upload</title></head><body><h1>Loading NCGA Index list.csv</h1>@FileUpload.GetHtml(initialNumberOfFiles:1,allowMoreFilesToBeAdded:false,includeFormTag:true,uploadText:"Upload")@if(IsPost&&fileName!=String.Empty){<span>File uploaded!</span><br/>}</body></html>