Friday 24 June 2016

create folder and file if missing in C#

 private static void CreateLogFileIfNotExist(string fullPath)
        {
            try
            {
                FileInfo fileInfo = new FileInfo(fullPath);
                if (!fileInfo.Directory.Exists)

                {
                    fileInfo.Directory.Create();
                }
                if (!File.Exists(fullPath))
                {
                    File.Create(fullPath).Dispose();
                }
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex.Message);
            }

        }

No comments:

Post a Comment