private bool SaveImages()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile postedFile = files[i];
string filename, fileExt, filesize;
filename = System.IO.Path.GetFileName(postedFile.FileName);
filesize = postedFile.ContentLength.ToString();
if (filename != "")
{
fileExt = System.IO.Path.GetExtension(filename);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端的文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + filename + "<br>");
strMsg.Append("上传文件的文件大小:" + filesize + "字节<br>");
strMsg.Append("上传文件的扩展名:" + fileExt + "<br><hr>");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\testFile\\");
if (!dir.Exists)
{
dir.Create();
}
postedFile.SaveAs(dir + filename);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch (Exception ex)
{
strStatus.Text = ex.Message;
return false;
}
}
{
HttpFileCollection files = HttpContext.Current.Request.Files;
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile postedFile = files[i];
string filename, fileExt, filesize;
filename = System.IO.Path.GetFileName(postedFile.FileName);
filesize = postedFile.ContentLength.ToString();
if (filename != "")
{
fileExt = System.IO.Path.GetExtension(filename);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端的文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + filename + "<br>");
strMsg.Append("上传文件的文件大小:" + filesize + "字节<br>");
strMsg.Append("上传文件的扩展名:" + fileExt + "<br><hr>");
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo("C:\\testFile\\");
if (!dir.Exists)
{
dir.Create();
}
postedFile.SaveAs(dir + filename);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch (Exception ex)
{
strStatus.Text = ex.Message;
return false;
}
}