예제 #1
0
        public DataContracts.FileTransfer.DC_UploadResponse TransferFileInChunks(DataContracts.FileTransfer.DC_FileData request)
        {
            try
            {
                DHSVC.DC_FileData file = new DHSVC.DC_FileData();
                file.FileName      = request.FileName;
                file.FilePostition = request.FilePostition;
                file.BufferData    = request.BufferData;

                object result = null;
                DHSVCProxy.PostData(ProxyFor.DataHandler, System.Configuration.ConfigurationManager.AppSettings["Data_Handler_Upload_File_InChunks"], file, file.GetType(), typeof(DataContracts.FileTransfer.DC_UploadResponse), out result);
                file = null;
                return(result as DataContracts.FileTransfer.DC_UploadResponse);
            }
            catch (Exception e)
            {
                return(new DataContracts.FileTransfer.DC_UploadResponse {
                    UploadedPath = string.Empty, UploadSucceeded = false
                });
            }
        }
예제 #2
0
        public DataContracts.FileTransfer.DC_UploadResponse UploadFileInChunks(DataContracts.FileTransfer.DC_FileData request)
        {
            try
            {
                var uploadDirectory = System.Configuration.ConfigurationManager.AppSettings["FileUploadLocation"].ToString();
                if (string.IsNullOrWhiteSpace(uploadDirectory))
                {
                    uploadDirectory = @"D:\UPLOAD\";
                }

                if (!Directory.Exists(uploadDirectory))
                {
                    Directory.CreateDirectory(uploadDirectory);
                }

                var FilePath = Path.Combine(uploadDirectory, request.FileName);

                if (request.FilePostition == 0)
                {
                    File.Create(FilePath).Close();
                }

                using (FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                {
                    fileStream.Seek(request.FilePostition, SeekOrigin.Begin);
                    fileStream.Write(request.BufferData, 0, request.BufferData.Length);
                }

                return(new DC_UploadResponse {
                    UploadedPath = FilePath, UploadSucceeded = true
                });
            }
            catch
            {
                return(new DC_UploadResponse {
                    UploadedPath = string.Empty, UploadSucceeded = false
                });
            }
        }