B
bhavya internship
Guest
Hello All,
I am reading the below path
C:\ProgramData\EMR\Registration\RegistrationSubset.xml using strFilePath parameter in the below ReadJsonFile function.
Now, my new requirement is, the same function should process array of paths and then loop through the array of path locations to find and read the available file path.
below is the array of paths. These paths are reading from .json file.
%programdata%\EMR\Registration\Registration_Subset.xml C:\ProgramData\EMR\Registration\RegistrationSubset.xml
%AppData%\EMR\EMR Setup\REGDATA\registration_subset.xml %AppData%\EMR\EMR Setup\REGDATA\RegistrationSubset.xml
Please help me how to read array of paths to find the available file path in the below function? And also how to resolve the path (i.e, while reading the path %programdata%\EMR how to change it to C:\programdata\EMR)?
Below is the code snippet:
bool EMRFileReader::ReadJsonFile(const std::wstring &strFilePath, std::wstring &strFileContent)
{
DWORD dwFileAttribute = FILE_ATTRIBUTE_NORMAL;
std::wstring strExtension = :athFindExtension(strFilePath.c_str());
if (strExtension.find(BLOB) != std::string::npos)
{
dwFileAttribute = FILE_ATTRIBUTE_ENCRYPTED;
}
HANDLE hFile = NULL;
LPBYTE lpData = NULL;
hFile = CreateFile(strFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, dwFileAttribute, NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
return false;
}
DWORD dwBytesReadWrite = 0, dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
lpData = new(nothrow) BYTE[dwFileSize];
if (lpData)
{
ReadFile(hFile, (LPVOID)lpData, dwFileSize, &dwBytesReadWrite, NULL);
}
CloseHandle(hFile);
if (dwBytesReadWrite > 0)
{
wstring strBase64;
string strData = string((char*)lpData);
EncodeBase64(dwBytesReadWrite, strData, strBase64);
strFileContent = strBase64;
}
if (lpData != NULL)
{
delete[] lpData;
}
return true;
}
Thank you,
Continue reading...
I am reading the below path
C:\ProgramData\EMR\Registration\RegistrationSubset.xml using strFilePath parameter in the below ReadJsonFile function.
Now, my new requirement is, the same function should process array of paths and then loop through the array of path locations to find and read the available file path.
below is the array of paths. These paths are reading from .json file.
%programdata%\EMR\Registration\Registration_Subset.xml C:\ProgramData\EMR\Registration\RegistrationSubset.xml
%AppData%\EMR\EMR Setup\REGDATA\registration_subset.xml %AppData%\EMR\EMR Setup\REGDATA\RegistrationSubset.xml
Please help me how to read array of paths to find the available file path in the below function? And also how to resolve the path (i.e, while reading the path %programdata%\EMR how to change it to C:\programdata\EMR)?
Below is the code snippet:
bool EMRFileReader::ReadJsonFile(const std::wstring &strFilePath, std::wstring &strFileContent)
{
DWORD dwFileAttribute = FILE_ATTRIBUTE_NORMAL;
std::wstring strExtension = :athFindExtension(strFilePath.c_str());
if (strExtension.find(BLOB) != std::string::npos)
{
dwFileAttribute = FILE_ATTRIBUTE_ENCRYPTED;
}
HANDLE hFile = NULL;
LPBYTE lpData = NULL;
hFile = CreateFile(strFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, dwFileAttribute, NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
return false;
}
DWORD dwBytesReadWrite = 0, dwFileSize;
dwFileSize = GetFileSize(hFile, NULL);
lpData = new(nothrow) BYTE[dwFileSize];
if (lpData)
{
ReadFile(hFile, (LPVOID)lpData, dwFileSize, &dwBytesReadWrite, NULL);
}
CloseHandle(hFile);
if (dwBytesReadWrite > 0)
{
wstring strBase64;
string strData = string((char*)lpData);
EncodeBase64(dwBytesReadWrite, strData, strBase64);
strFileContent = strBase64;
}
if (lpData != NULL)
{
delete[] lpData;
}
return true;
}
Thank you,
Continue reading...