I've programmed a console app using C# as means to troubleshoot an issue with an SSIS Script Task. My thought is that I can debug with a bit more clarity in the console app and then implement the code in the Script Task.
I've programmed a console app using C# as means to troubleshoot an issue with an SSIS Script Task. My thought is that I can debug with a bit more clarity in the console app and then implement the code in the Script Task.
I've programmed a console app using C#.
How to Remedy Error System.UnauthorizedAccessException in My Console App?
I've programmed a console app using C# as means to troubleshoot an issue with an SSIS Script Task. My thought is that I can debug with a bit more clarity in the console app and then implement the code in the Script Task.
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?
lang-cs