Beispiel #1
0
        /// <summary>
        /// 调用WCF下载文件
        /// </summary>
        /// <param name="fileName"></param>
        private void DownFile(DifferentFile file)
        {
            Stream sm        = new MemoryStream();
            var    name      = file.FullName.Substring(file.AbsoulteRootPath.Length - 1);
            var    msg       = string.Empty;
            var    size      = 0l;
            var    issuccess = MemexUpateHelper.DownLoadFile(name, textBox1.Text, out msg, out size, out sm);

            if (issuccess.IsSuccess)
            {
                if (file.DiffentValue == DifDescription.FileNotExistInClient && !Directory.Exists(file.ClientFullPath))
                {
                    Directory.CreateDirectory(file.ClientFullPath);
                }
                var filePath = string.Empty;
                filePath = file.DiffentValue == DifDescription.FileNotExistInClient ? file.ClientFullPath + "\\" + file.FilName : file.ClientFullPath;

                byte[]     buffer = new byte[size];
                FileStream fs     = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                try
                {
                    int count = 0;
                    while ((count = sm.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fs.Write(buffer, 0, count);
                    }
                    fs.Flush();
                    fs.Close();
                }
                finally {
                    ((IDisposable)fs).Dispose();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 调用WCF下载文件
        /// </summary>
        /// <param name="fileName"></param>
        private void DownFile(DifferentFile file)
        {
            Stream sm        = new MemoryStream();
            var    name      = file.FullName.Substring(file.AbsoulteRootPath.Length - 1);
            var    msg       = string.Empty;
            var    size      = 0l;
            var    issuccess = this.DownLoadFile(name, out msg, out size, out sm);

            if (issuccess.IsSuccess)
            {
                if (file.DiffentValue == DifDescription.FileNotExistInClient && !Directory.Exists(file.ClientFullPath))
                {
                    Directory.CreateDirectory(file.ClientFullPath);
                }
                var filePath = string.Empty;
                filePath = file.DiffentValue == DifDescription.FileNotExistInClient ? file.ClientFullPath + "\\" + file.FilName : file.ClientFullPath;

                byte[] buffer = new byte[size];

                FileStream fs;
                try
                {
                    fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);

                    int count = 0;
                    while ((count = sm.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fs.Write(buffer, 0, count);
                    }
                    fs.Flush();
                    fs.Close();
                }
                catch (Exception ex2)
                {
                    MessageBox.Show("写入文件时出错.file:" + filePath + "\n" + ex2.ToString());
                }
            }
        }