EDITED: Apologies for the errors - I understand a wan't super clear.
I have created a class library which i want to fill with multiple methods/functions. I am working on one of those methods however i am struggling to use the method using a custom directory.
See Code of method in class library:
public class SharpFuntions
{
public static void CreateFile(string location){
string path = location;
try
{
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
// Create the file.
File.Create(path);
{
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
Now when i try and call this function and use a directory, it doesnt pass. See below:
static void Main(string[] args)
{
SharpFuntions.CreateFile(@"C:\User\Text.txt");
}
I'm not sure if the above is even possible. I just want to be able to call the function and possibly be able to insert a different Directory/filename each time I use it.
So the below works which i know, However I dont want to Hardcode the Directory/Filename
public class SharpFuntions
{
public static void CreateFile(){
string path = @"c:\temp\MyTest2.txt";
try
{
// Delete the file if it exists.
if (File.Exists(path))
{
File.Delete(path);
}
// Create the file.
File.Create(path)
{
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}