图片由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;
高手帮看看什么问题,或者有什么解决办法
请教一个这个问题怎么解决,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;
高手帮看看什么问题,或者有什么解决办法
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货