which works good other than the line about adding the row to the log will not work because it is out of the context.
I tried putting this block of code into the main part of the code, but it will not work.
ideas?
Thanks.
.NET ProgrammingC#
Last Comment
wiggy353
8/22/2022 - Mon
SAMIR BHOGAYTA
Hi, try this
using System;
using System.IO;
class Test
{
public static void Main()
{
// Specify the directories you want to manipulate.
string path = @"c:\MyDir";
string subPath = @"c:\MyDir\temp";
try
{
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
// Create the directory.
Directory.CreateDirectory(path);
}
if (!Directory.Exists(subPath))
{
// Create the directory.
Directory.CreateDirectory(subPath);
}
// This will succeed because subdirectories are being deleted.
Console.WriteLine("I am about to attempt to delete {0}", path);
if(Directory.ContentLength >0)
{
Directory.Delete(path, true);
Console.WriteLine("The Delete operation was successful.");
}
If you are talking about the current context of a web page you could pass it into the static method by adding a parameter HttpContext currentContext and proving HttpContext.Current when you invoke the method. Otherwise, you could pass a reference to the log when you call the static method - that would allow you to update it.
wiggy353
ASKER
samirbhogayta,
This will not work at all. It is not addressing any of the issues that I am working with. I do not know the names of the sub directories, and don't need to. I just need to delete them if they are empty. I do not want to write any lines of text to the console, I need to add rows to a table. I have read the text you posted on other web pages. It is not what I am looking for.
MajorBigDeal,
It is not dealing with a web page. It is not is the same context because the method that I posted is outside of the context of the main method which has the log table in it.
using System;
using System.IO;
class Test
{
public static void Main()
{
// Specify the directories you want to manipulate.
string path = @"c:\MyDir";
string subPath = @"c:\MyDir\temp";
try
{
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
// Create the directory.
Directory.CreateDirectory(
}
if (!Directory.Exists(subPath
{
// Create the directory.
Directory.CreateDirectory(
}
// This will succeed because subdirectories are being deleted.
Console.WriteLine("I am about to attempt to delete {0}", path);
if(Directory.ContentLength
{
Directory.Delete(path, true);
Console.WriteLine("The Delete operation was successful.");
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally {}
}
}