FVSDK_ERROR_CODE FVSDK_CloseFile(FVSDK_Session* pSession);
Performs cleanup for any file opened with FVSDK_OpenFile(), FVSDK_CreateFile(), or FVSDK_OpenFileRW(). After opening a file, this function must be called before any other file is created or opened.
pSession
A pointer to the FVSDK_Session that is to perform the operation.
FVSDK_YES if the function was successful; FVSDK_NO if an error occurred, or the server did not respond with a "successful" completion response. Error codes can be found in FVSDK_ErrorCodes.h.
CStdioFile File;
FVSDK_Session* pSession;
CString sRemoteName;
// ... upload preparation ...
// get the local file size
FVSDK_FILE_SIZE fsLocalFileSize = File.GetLength();
// create the file to be uploaded on the server
if (FVSDK_CreateFile(pSession, sRemoteName, TRUE, 0) == FVSDK_YES) {
BYTE Buffer[1024];
int nBytes;
FVSDK_FILE_SIZE fsWritten = 0;
// read all of the data from the local file, and write it to the remote file
while ((nBytes = File.Read(Buffer, sizeof(Buffer))) > 0) {
// do the write
if (FVSDK_WriteFile(pSession, Buffer, &nBytes, ((nBytes + fsWritten) >= fsLocalFileSize)) != FVSDK_YES) {
// put up an error message
AfxMessageBox("Unable to write to the remote file", MB_ICONEXCLAMATION);
// get out
break;
} // if
// increment the number of bytes written to the file
fsWritten += nBytes;
} // while
// close the remote file
if (FVSDK_CloseFile(pSession) == FVSDK_YES) {
CFileStatus Status;
// get the status of the local file, then set the date and time of the remote file
if (File.GetStatus(Status)) {
tm tmLocalTime;
// get the last time the file was modified
Status.m_mtime.GetLocalTm(&tmLocalTime);
// set the date and time of the remote file, put up an error if it fails
if (FVSDK_SetFileDateAndTime(pSession, sRemoteName, &tmLocalTime) != FVSDK_YES)
AfxMessageBox("Unable to set the remote file's date and time.", MB_ICONEXCLAMATION);
} // if
} // if
else {
AfxMessageBox("Unable to close the remote file", MB_ICONEXCLAMATION);
} // if
else
AfxMessageBox("Unable to create the remote file", MB_ICONEXCLAMATION);
// ... upload cleanup ...