get directory of file c#
using System.IO;
string file = "C:\Documents\file.txt";
Path.GetDirectoryName(file);
get directory of file c#
using System.IO;
string file = "C:\Documents\file.txt";
Path.GetDirectoryName(file);
get folders in directory c#
string[] folders = System.IO.Directory.GetDirectories(@"C:\My Sample Path\","*", System.IO.SearchOption.AllDirectories);
get user directory of file in c#
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
// TODO: Use LocalUser instead of Hardcode
openFileDialog.InitialDirectory = @"C:\Users\username\Desktop";
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
filePath = openFileDialog.FileName;
//Read the contents of the file into a stream
var fileStream = openFileDialog.OpenFile();
using (StreamReader reader = new StreamReader(fileStream))
{
fileContent = reader.ReadToEnd();
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us