I have a edit box( editable), where user can provide relative path like (..\..\folder\Ranjitha). I have one Save button. On Click of this button i will get the absolute folder path.
Now my question is how i can check the relative path with the absolute folder path ? I need to provide a check whether the relative path is available or not in the absolute path.
Loading
Sam HobbsPosted Apr 6, 2010, 2:52 PM
Ranjitha C NPosted Apr 7, 2010, 12:13 AM
Ranjitha C NPosted Apr 5, 2010, 11:32 PM
Ranjitha C NPosted Apr 5, 2010, 11:28 PM
Thanks for replying.. I am using VC.Net 2003 with MFC (VC++). I got the solution and my project is working fine now.. Following the code what i did for checking relative path with respect to Base directory.
BOOL CGwConfData::CheckRelativePath(CString strRelPath)
{
CString strBaseDir; // Base directory " Ex: D:/My Projects/All Codes/Present Code"
strBaseDir = m_strConfigPath;
CString str1;
int nPos = 0;
nPos = strRelPath.Find(':'); // Checking whether the path is relative path or full path
if(strBaseDir != "" || nPos != -1) // If it is relative path and has base directory path
{
SetCurrentDirectory(strBaseDir); // Setting base directory path
TCHAR lpBuffer1[MAX_PATH];
LPTSTR lpFname1 = NULL;
// GetFullPathName("..\\..\\MCM2_Unit_test_tracker_CW50_091.xls",MAX_PATH,
// lpBuffer1,&lpFname1);
// Relative path Ex : "..\\..\\MCM2_Unit_test_tracker_CW50_091.xls" - Here "../" means 1 folder previous in base directory so
// here the path is "D:/My Projects/MCM2_Unit_test_tracker_CW50_091.xls".
GetFullPathName(strRelPath, MAX_PATH, lpBuffer1, &lpFname1); // Getting fullpath from base directory
CString str1 = lpBuffer1;
BOOL bExists = PathFileExists(str1); // Checking whether relative path file exist in base directory
if(bExists == FALSE)
{
CString strFormat;
strFormat.Format("%s%s%s", STR_CD_FILEINFO, strRelPath, STR_CD_FILEINFO_END);
MessageBox(NULL, strFormat, STR_GWAPP, MB_OK | MB_ICONINFORMATION );
return FALSE;
}
else
return TRUE;
}
return TRUE;
}
Sam HobbsPosted Apr 5, 2010, 11:02 AM
Amit ChoudharyPosted Apr 5, 2010, 12:56 AM
you can use Server.MapPath(@"~/folder/Ranjitha") to get the absolute path...