思路:1.选择并保存多个图片的文件路径
2.使用FTP的方式上传关键代码: public bool Upload(string filePath)//上传的
{
FileStream fs = null;
Stream stream = null;
try
{
FileInfo info = new FileInfo(filePath);
FtpWebRequest reqFtp = GetFtpWebRequest(info.Name); int buffLength = 2048;
byte[] buff = new byte[buffLength];
fs = info.OpenRead();
stream = reqFtp.GetRequestStream();
int contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
stream.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
return true;
}
catch (Exception)
{
return false;
}
finally
{
if (fs != null)
{
fs.Close();
}
if (stream != null)
{
stream.Close();
}
}
} protected void btnUpload_Click(object sender, EventArgs e)//页面点击上传按钮的时候的
{
FtpUploader ftp = new FtpUploader();
foreach (string s in imgList)
{
ftp.Upload(s);
}
imgList.Clear();
}
注意,这个例子是用FtpWebRequest,也就是FTP的上传方式,如果想用这种办法,必须先配置好ftp
哈哈,大家有更好的办法就多多指教啊!
下载示例
2.使用FTP的方式上传关键代码: public bool Upload(string filePath)//上传的
{
FileStream fs = null;
Stream stream = null;
try
{
FileInfo info = new FileInfo(filePath);
FtpWebRequest reqFtp = GetFtpWebRequest(info.Name); int buffLength = 2048;
byte[] buff = new byte[buffLength];
fs = info.OpenRead();
stream = reqFtp.GetRequestStream();
int contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
stream.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
return true;
}
catch (Exception)
{
return false;
}
finally
{
if (fs != null)
{
fs.Close();
}
if (stream != null)
{
stream.Close();
}
}
} protected void btnUpload_Click(object sender, EventArgs e)//页面点击上传按钮的时候的
{
FtpUploader ftp = new FtpUploader();
foreach (string s in imgList)
{
ftp.Upload(s);
}
imgList.Clear();
}
注意,这个例子是用FtpWebRequest,也就是FTP的上传方式,如果想用这种办法,必须先配置好ftp
哈哈,大家有更好的办法就多多指教啊!
下载示例
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货