Esempio n. 1
0
        /// <summary>
        /// 上传文件(对客户端来说)
        /// </summary>
        /// <param name="fileWrapper">WCF.ServiceLib.Message.FileWrapper</param>
        public void UploadFile(FileWrapper fileWrapper)
        {
            string filename = Path.GetFileNameWithoutExtension(fileWrapper.FilePath);
            string fileext  = Path.GetExtension(fileWrapper.FilePath);
            string newpath  = Path.Combine(incomingfolder, filename + fileext);

            var sourceStream = fileWrapper.FileData;

            if (File.Exists(newpath))
            {
                throw new System.Exception(DateTime.Now.ToLongTimeString() + "上传文件已经存在:" + newpath);
            }


            try
            {
                var targetStream = new FileStream(newpath,
                                                  FileMode.Create,
                                                  FileAccess.Write,
                                                  FileShare.None);

                var buffer = new byte[4096];
                var count  = 0;

                while ((count = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    targetStream.Write(buffer, 0, count);
                }

                targetStream.Close();
                sourceStream.Close();

                LogEntry log = new LogEntry();
                log.Message = newpath + "上传成功.";
                log.Categories.Add("文件上传");
                Logger.Write(log);

                Console.WriteLine(DateTime.Now.ToLongTimeString() + log.Message);
                return;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="fileWrapper">WCF.ServiceLib.Message.FileWrapper</param>
        public void UploadFile(FileWrapper fileWrapper)
        {
            var sourceStream = fileWrapper.FileData;

            var targetStream = new FileStream(fileWrapper.FilePath,
                FileMode.Create,
                FileAccess.Write,
                FileShare.None);

            var buffer = new byte[4096];
            var count = 0;

            while ((count = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                targetStream.Write(buffer, 0, count);
            }

            targetStream.Close();
            sourceStream.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="fileWrapper">WCF.ServiceLib.Message.FileWrapper</param>
        public void UploadFile(FileWrapper fileWrapper)
        {
            var sourceStream = fileWrapper.FileData;

            var targetStream = new FileStream(fileWrapper.FilePath,
                                              FileMode.Create,
                                              FileAccess.Write,
                                              FileShare.None);

            var buffer = new byte[4096];
            var count  = 0;

            while ((count = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                targetStream.Write(buffer, 0, count);
            }

            targetStream.Close();
            sourceStream.Close();
        }