我不能使用fileUpload.PostedFiles[]
财产?
我实际上需要一个多文件上传器和调整大小。
我对所有文件都使用HttpFileCollection
hfc。它总是错的string filename = fileUpload
。
这是一个好方法吗?
protected void UploadFile_Click(object sender, EventArgs e)
{
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
if (fileUpload.HasFile)
{
**string filename=fileUpload.PostedFiles[i].FileName;**
string directory = Server.MapPath(@"Uploaded-Files\");
Bitmap originalBMP = new Bitmap(fileUpload.FileContent);
Bitmap newBMP = new Bitmap(originalBMP, 800, 480);
Graphics oGraphics = Graphics.FromImage(newBMP);
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
newBMP.Save(directory + "tn_" + filename);
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();
}
}
}
}