Beispiel #1
0
        /// <summary>
        /// 追加二进制数据到文件
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="curLength"></param>
        private void AppendFile(ArraySegment <byte> buffer, int curLength)
        {
            string filename = _file.GetFullName();

            try
            {
                FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
                try
                {
                    byte[] data = buffer.ToArray();
                    fs.Write(data, 0, curLength);
                }
                finally
                {
                    fs.Close();
                    fs.Dispose();
                }
                FileInfo info = new FileInfo(filename);
                if (info.Length >= _file.ContentLength)//保存文件成功
                {
                    if (OnSuccess != null)
                    {
                        OnSuccess(_file);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("服务保存文件异常," + ex.Message);
            }
        }
Beispiel #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="info">上传文件信息</param>
 public ThumbnailHandle(UploadInfo info, string folder, int width)
 {
     this.Folder   = folder;
     this._Info    = info;
     this.FullName = info.GetFullName();
     if (string.IsNullOrEmpty(info.GetSubFolder()))
     {
         throw new Exception("缩略图处理模式,上传子目录不能为空");
     }
     this.Width = width;
 }