Please find below code that i have written:
private void WriteLogs(Guid _guid)
{
string varpath = ConfigurationManager.AppSettings["LogFilePath"].ToString() + @"\ErrorLogs\Logs\";
string FileName = _guid.ToString() + ".txt";
string finalPath = System.IO.Path.GetFullPath(varpath + FileName);
if (Path.GetDirectoryName(finalPath) == Path.GetDirectoryName(varpath))
{
if (!Directory.Exists(varpath))
{
Directory.CreateDirectory(varpath);
}
// Other code
}
}
Please let me know does this code prevent Directory Traversal flaw?