0

I've programmed a console app using C#.

When I run the console app I receive the error noted above. My programming logic is as follows:

class Program { static void Main(string[] args) { string path = @"\\mypath\\mydirectory"; DirectoryInfo di = new DirectoryInfo(path); FileInfo[] files = di.GetFiles(); string year = DateTime.Now.Year.ToString(); string month = DateTime.Now.Month.ToString("d2"); string day = DateTime.Now.Day.ToString("d2"); string feedVersion; string manifestFileName = "MyFile_" + year + month + day + ".manifest"; string manifestDest = di + manifestFileName; string manifestHeader = "FileName|Version|Line_Count|SHA256HASH"; StreamWriter oFile = new StreamWriter(manifestDest); FileStream uploadFile = File.OpenWrite(manifestFileName); using (SHA256 mySHA256 = SHA256.Create()) { oFile.WriteLine(manifestHeader); foreach (FileInfo finfo in files) { if (finfo.Name.Contains("labdata")) { feedVersion = "200"; } else if (finfo.Name.Contains("pharm")) { feedVersion = "200"; } else if (finfo.Name.Contains("claim")) { feedVersion = "200"; } else if (finfo.Name.Contains("enrollment")) { feedVersion = "220"; } else if (finfo.Name.Contains("member")) { feedVersion = "202"; } else if (finfo.Name.Contains("provider")) { feedVersion = "220"; } else if (finfo.Name.Contains("hierarchy")) { feedVersion = "200"; } else if (finfo.Name.Contains("member*attribution")) { feedVersion = "200"; } else { feedVersion = "NA"; } using (uploadFile) { try { var lineCount = File.ReadAllLines(di.ToString()); var fileName = Path.GetFileName(di.ToString()); byte[] hashValue = mySHA256.ComputeHash(uploadFile); //Console.Write($"{finfo.Name}: "); oFile.WriteLine(fileName.ToString() + "|" + feedVersion.ToString() + "|" + lineCount.ToString() + "|" + hashValue); } catch (Exception ex) { Console.WriteLine(ex.Message); } } oFile.Close(); oFile.Dispose(); } } Console.WriteLine("Success"); } public static void PrintByteArray(byte[] array) { for (int i = 0; i < array.Length; i++) { Console.Write($"{array[i]:X2}"); if ((i % 4) == 3) Console.Write(" "); } Console.WriteLine(); } } 

What modifications are needed to ensure that the file can be created in the directory as specified and that it contains all the needed information in it?

3
  • 1
    Assuming you are debugging this from Visual Studio, Does user running this process (most probably your windows user) have full access on the path your application is trying to access ? Some times organization GPOs don't allow any modification on the C: drive. If your folder is on the C: drive try to put it on the D: drive and see if that helps. Commented Feb 27, 2024 at 18:53
  • @AP Thanks for this guidance. I've tried using several network locations, both inside my development environment and in the production file system all to no avail. Commented Feb 27, 2024 at 19:54
  • File.ReadAllLines(di.ToString()) is the problem, you can't read a directory like it is a file. Commented Feb 27, 2024 at 20:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.