Answered by:
checking if a file exists

Question
-
User-2012457684 posted
I want to write some code to read the iis logfiles on the server so clients can get some information. The client will be able to pick a date range and get the infromation based on that. To that end I want to check to see if the log file exists. For some reason i am getting an erro and don't understand what is wrong
using System.IO; ....snip [HttpPost] public ActionResult Index(DateTime StartDate, DateTime EndDate) { List<String> logList = new List<String>(); foreach (DateTime day in EachDay(StartDate, EndDate)) { string d = day.Day.ToString("00"); string m = day.Month.ToString("00"); string yr = day.Year.ToString().Substring(2); string logfile = "u_ex" + yr + m + d + ".log"; logList.Add(logfile); } var processID = Request.ServerVariables["INSTANCE_ID"]; string path = @"c:\inetpub\logs\logfiles\w3svc" + processID.ToString(); if(Directory.Exists(path)) { foreach(string log in logList) { string LogFile = path + @"\" + log; if (File.Exists(LogFile)) { } } } return View(); }
shows the following in the Error List
'Controller.File(byte[], string)' is a method, which is not valid in the given context
As usual I don't understand what it is trying to tell me.
Thursday, August 13, 2020 7:39 PM
Answers
-
User-2012457684 posted
I found the answer i needed to use
if (System.IO.File.Exists(LogFile)) { }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 13, 2020 8:50 PM
All replies
-
User1120430333 posted
It's saying that Controller is an object, it has a method called File() and somewhere in code you're not using it as an object with a method.
Thursday, August 13, 2020 7:46 PM -
User-2012457684 posted
That is in the controller inside of the Index method
File is a class in System.IO Exists is a method of the class
so it makes no damn sense
Thursday, August 13, 2020 8:23 PM -
User-2012457684 posted
I found the answer i needed to use
if (System.IO.File.Exists(LogFile)) { }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 13, 2020 8:50 PM -
User1120430333 posted
That is in the controller inside of the Index method
File is a class in System.IO Exists is a method of the class
so it makes no damn sense
I would say fully qualify it giving the namespace File really lives in maybe it will work.
if (System.IO.File.Exists(LogFile)) { }
Thursday, August 13, 2020 8:54 PM -
User784298167 posted
I have been use the mvc controller to do that and I already use this for lightweight canoe paddles and it works
@using (Html.BeginForm("FileUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.ValidationSummary(); <ol> <li class="lifile"> <input type="file" id="fileToUpload" name="file" /> <span class="field-validation-error" id="spanfile"></span> </li> </ol> <input type="submit" id="btnSubmit" value="Upload" /> }
Monday, August 24, 2020 7:13 PM