重复载入图片

三碗猪脚 2008-04-13 11:01:50
图片由FTP下载下来,再填充到pictureBox,发现第一次载入可以,但是重复载入时就提示该文件正在一个进程访问,
请教一个这个问题怎么解决,3Q



private void Download(string filePath, string fileName)
{
FtpWebRequest reqFTP;


try
{
FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));

reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;

reqFTP.UseBinary = true;

reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();

Stream ftpStream = response.GetResponseStream();

long cl = response.ContentLength;

int bufferSize = 2048;

int readCount;

byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);

while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);

readCount = ftpStream.Read(buffer, 0, bufferSize);
}

ftpStream.Close();

outputStream.Close();

response.Close();

ftpStream.Dispose();
outputStream.Dispose();
GC.SuppressFinalize(this);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}

string filePathAndName = "E:\\StuPhoto" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".jpg";
Download("E:\\StuPhoto", this.txtSearchInputStuID.Text + ".jpg");
System.Drawing.Image tempStuPhoto = (System.Drawing.Image)(Bitmap.FromFile(("E:\\StuPhoto\\" + this.txtSearchInputStuID.Text + ".jpg")));
System.Drawing.Image stuPhoto = (System.Drawing.Image)(tempStuPhoto.Clone());
tempStuPhoto.Dispose();
this.picBoxStuPhoto.Image = stuPhoto;


高手帮看看什么问题,或者有什么解决办法
...全文
90 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
三碗猪脚 2008-04-14
  • 打赏
  • 举报
回复
自顶一下,别沉了
三碗猪脚 2008-04-14
  • 打赏
  • 举报
回复
不是,有的时候想重新下载。。。。
lg20056329 2008-04-14
  • 打赏
  • 举报
回复
你这个是不是将他做成FLASH的效果呀
三碗猪脚 2008-04-13
  • 打赏
  • 举报
回复
第二段代码偿试用复制的方法好像也不行。。。

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧