我有以下 C# 代码(关于将文件上传到服务器)
for (int i = 0; i < Request.Files.Count-1; i++)
{
if (Request.ContentLength != 0)
{
int Size = Request.Files[i].ContentLength / 1024;
if (Size <= 512)
{
string LocalFile = Request.Files[i].FileName;
int dot = LocalFile.LastIndexOf('.');
string FileType = LocalFile.Substring(dot + 1);
if (FileType == "gif" || FileType == "jpg" || FileType == "png" || FileType == "GIF" || FileType == "JPG" || FileType == "PNG")
{
int LastIndex = LocalFile.LastIndexOf(@"\") + 1;
string File = LocalFile.Substring(LastIndex, LocalFile.Length - LastIndex);
string Path = Server.MapPath(" ../images/tracks") + "..\\" + File;
Request.Files[i].SaveAs(Path);
if (i != Request.Files.Count - 1)
ImageList += string.Format("images/tracks/{0}|", File);
else { ImageList += string.Format("images/tracks/{0}", File); }
}
}
else
{
Response.Write("The file is too big !");
}
}
else
{
Response.Write("Unknown Error !");
}
}
问题是文件上传字段不止一个。
我想创建条件,它将检查 file[i] 之后是否有文件(如果 file[i+1] 为空,则检查)如果是,程序将执行以下代码:ImageList += string.Format("images/tracks/{0}", File);
别的:ImageList += string.Format("images/tracks/{0}|", File);
我的问题是情况应该是什么样子?
求帮助,谢谢!