/// <summary> /// Call this to say that the upload is complete. /// The returned FileUploadInfo.TempFileName gives you the actual file that has been uploaded. /// FileUploadInfo.FileName tells you what that file should be called (was originally called on the client). /// You should call UploadReset() when you have finished with the temp file. /// </summary> /// <param name="logonId">Logon id of user</param> /// <param name="TransferId">Transfer id</param> /// <returns></returns> public static FileUploadInfo UploadComplete(Guid logonId, Guid TransferId) { FileTransferData FileTransferData = Host.GetFileTransferData(logonId); if (!FileTransferData.IsUpload) { throw new Exception("File upload has not been started"); } if (FileTransferData.TransferId != TransferId) { throw new Exception("Transfer id does not match"); } if (FileTransferData.FileStream == null) { throw new Exception("File upload has not been started or has timed out"); } FileTransferData.FileStream.Close(); FileUploadInfo FileUploadInfo = new FileUploadInfo(); try { if (new FileInfo(FileTransferData.TempFileName).Length != FileTransferData.Size) { throw new Exception("File upload failed, file size is wrong"); } byte[] LocalHash = FileTransferHash.CreateFileMD5Hash(FileTransferData.TempFileName); if (!FileTransferHash.CheckHash(LocalHash, FileTransferData.Hash)) { throw new Exception("File upload failed, checksum does not match"); } File.SetLastWriteTime(FileTransferData.TempFileName, FileTransferData.ModifiedDate); FileUploadInfo.TempFileName = FileTransferData.TempFileName; FileUploadInfo.FileName = FileTransferData.FileName; FileUploadInfo.ModifiedDate = FileTransferData.ModifiedDate; FileUploadInfo.Size = FileTransferData.Size; } catch { FileTransferData.Reset(); throw; } return(FileUploadInfo); }
public ReturnValue DocumentUploadComplete(Guid logonId, Guid TransferId) { ReturnValue ReturnValue = new ReturnValue(); try { // Get the logged on user from the current logons and add their // ApplicationSettings the list of concurrent sessions. Host.LoadLoggedOnUser(logonId); try { FileUploadInfo FileUploadInfo = FileTransfer.UploadComplete(logonId, TransferId); DocumentStorageData DocumentStorageData = Host.GetDocumentStorageData(logonId); // DocumentStorageData holds all the information needed to know how to store the document // TODO this is just test code. You should replace this with code to store the file // in the ILB document management system. // FileUploadInfo.TempFileName holds the full path to the actual file that has been uploaded // FileUploadInfo.FileName holds the original file name (excluding path) of the file that has been uploaded // The file will need moving to the correct location in the document management system. File.Move(FileUploadInfo.TempFileName, @"c:\Work\Uploaded\" + FileUploadInfo.FileName); FileTransfer.UploadReset(logonId, TransferId); } finally { // Remove the logged on user's ApplicationSettings from the // list of concurrent sessions Host.UnloadLoggedOnUser(); } } catch (Exception ex) { ReturnValue.Success = false; ReturnValue.Message = ex.Message; } return(ReturnValue); }