【原创】几行代码实现上传
没有什么新鲜的东西,只是些简单的东西,代码非常简单,我就没加注释了。
string Path = Server.MapPath("~/Upload/");
if (FileUpload1.HasFile)
{
string FileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
string[] FileAllExtension ={ ".jpg", ".gif", ".bmp" };
foreach (string s in FileAllExtension)
{
if (FileExtension == s)
{
FileUpload1.PostedFile.SaveAs(Path + Guid.NewGuid().ToString() + FileExtension);
}
}
}
if (FileUpload1.HasFile)
{
string FileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
string[] FileAllExtension ={ ".jpg", ".gif", ".bmp" };
foreach (string s in FileAllExtension)
{
if (FileExtension == s)
{
FileUpload1.PostedFile.SaveAs(Path + Guid.NewGuid().ToString() + FileExtension);
}
}
}