Friday, 15 March 2013

.net - C# Cannot Create Directory -


I can not seem to get the code to work:

  System ; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.IO; Namespace TechKit {square CsvWriter {public static void csvLogWrite (string ADName, string LogTimeStamp, string LogEntry, string ATOW, string SSC, string attribute) {string dirPath = Path.GetDirectoryName (Properties.Settings.Default.TechKitSDFLocation); DirPath = Path.Combine (dirPath, "Log", DateTime.Now.Year.ToString ()); Try {// Determine if the directory exists or not. If (Directory.Exists (dirPath)) {Console.WriteLine ("Log Path Exisits - Use It"); Return; } // Try creating directories DirectoryInfo di = Directory.CreateDirectory (dirPath); Console.WriteLine ("successfully created in the log directory {0}.", Directory.GetCreationTime (dirPath)); } Hold (exception e) {Console.WriteLine ("The process of making the directory failed: {0}", E. toastring ()); } Finally {} string newFileName = DateTime.Now.Month.ToString () + ".csv"; String compound = path. Cobain (diaper path, newfile name); String logDetails = LogTimeStamp + "," + specialty + "," + ADName + "," + LogEntry + Environment.NewLine; if (! File.Exists (combinedPath)) {string logHeader = "Timestamp, specialty, name, log entry '+ Environment.NewLine; file. Likensbi text (Nyafailnam, Loghaider);} file. Exception text (Snyuktpth, logs, details); Kansolkprkash line ( "data written CSV file:"); Console.WriteLine (logDetails); Console.WriteLine ( "******************* *************}}}   

I get an exception when I try to write the code non-existent directory I get:

  'first instance of type exception' System.NotSupportedException 'mscorlib.dll In ''   

Also in the console. I have a relative I am an amateur, so I'm at a loss. Well, I could write a file, just a directory.

Thank you ...

Check directory path and then right of reading / writing it check.

and then use some code like this

  DirectoryInfo dir = new DirectoryInfo (dirPath); or System.IO.Director.CreateDirectory ( "Directory Path ")    

No comments:

Post a Comment