下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
/// <summary>
/// 单文件上传
/// </summary>
/// <param name="file">文件上传控件</param>
/// <param name="filetype">文件类型限制 例:new string[]{"image/gif","image/pjpeg"}</param>
/// <param name="fileLength">文件大小限制[KB]</param>
/// <param name="fullPath">文件要上传到的文件夹[全路径,不要带末尾的"\"] 例:Server.MapPath("../uploads")</param>
/// <returns>上传后的文件名</returns>
static public string Upload(System.Web.UI.WebControls.FileUpload file, string[] filetype, int fileLength, string fullPath){
bool checkType = false;
foreach (string str in filetype){
if(file.PostedFile.ContentType.ToString()==str){
checkType=true;
break;
}
}
if (!checkType){
return "错误:您上传的文件是不允许的类型";
}else{
if (file.PostedFile.ContentLength > fileLength * 1024){
return "错误:文件超出大小限制!";
}else{
Random rand = new Random(unchecked((int)DateTime.Now.Ticks));
string extender = Path.GetExtension(file.PostedFile.FileName);
string filename = DateTime.Now.ToShortDateString().Replace("-", "") + rand.Next().ToString().Substring(0,