C # Directory.CreateDirectory stops working

I have a C # application, it works correctly on many computers, laptops. But, I copied to my client PC (4TB HDD - Windows 10 Home Edition), my application stopped working!

I am trying to put MessageBox.Show()on some line to find where it is broken. And he stops atDirectory.CreateDirectory(@"D:\\mypath")

The PC has it D:, and I don’t know why it broke.

Here is my code:

string now = DateTime.Now.ToString("HH_mm_ss");
string strDuongDan;

strDuongDan = @"D:\VideoLuuTru\" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString();

if (!Directory.Exists(strDuongDan))
    Directory.CreateDirectory(strDuongDan);

string strDuongDan2 = strDuongDan + "\\" + DateTime.Now.ToString("dd"); ;

if (!Directory.Exists(strDuongDan2))
    Directory.CreateDirectory(strDuongDan2);

How can I accurately track my errors and something is wrong from my code? It works great on many PCs, but it broke with that PC.

Is my problem with a large hard drive?

My client IT staff installed my application on their laptop (Windows 10 Home) and installed the same windows on this computer. My application runs on his laptop without errors

Thanks you!

EDIT: :

:

 public void makevideo()
        {
            string now = DateTime.Now.ToString("HH_mm_ss");
            string strDuongDan;

            strDuongDan = @"D:\VideoLuuTru\" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString();

            if (!Directory.Exists(strDuongDan))
                Directory.CreateDirectory(strDuongDan);

            string strDuongDan2 = strDuongDan + "\\" + DateTime.Now.ToString("dd"); ;
            if (!Directory.Exists(strDuongDan2))
                Directory.CreateDirectory(strDuongDan2);
        }

 ThreadStart childref = new ThreadStart(() => makevideo());

 Thread childThread = new Thread(childref);

 try { childThread.Start(); }
 catch (Exception ex)
 {
     MessageBox.Show(ex.ToString());
  }

: **

Application: camera.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. 
Exception Info: System.IO.FileNotFoundException at camera.Form1.makevideo() at camera.Form1.<Form1_Load>b__6_0() at         System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, 
System.Threading.ContextCallback, System.Object) at 
System.Threading.ThreadHelper.ThreadStart()

**

+4
1

,

, MessageBox. ,

, , , , .

, , , . ,

try
{
    // Note you don't need to check if a directory exists before you create it
    // it does it for you
    // if (!Directory.Exists(strDuongDan))
    Directory.CreateDirectory(strDuongDan);
}
catch(Exception ex)
{
   // log here
   // or
   MessageBox.Show("Error : " + ex.Message)
}

Directory.CreateDirectory Method (String)

  • IOException

    • , , .
    • .
  • UnauthorizedAccessException

    • .
  • ArgumentException

    • path - , . GetInvalidPathChars.

    • path (:).

  • ArgumentNullException

    • null.
  • PathTooLongException

    • , , . , Windows 248 , 260 .
  • DirectoryNotFoundException

    • (, ).
  • NotSupportedException

    • path contains a colon character (:), which is not part of the drive label ("C: \").
+6
source

Source: https://habr.com/ru/post/1695642/


All Articles