您的位置首页生活快答

FileUpLoad控件

FileUpLoad控件

的有关信息介绍如下:

FileUpLoad控件

没遇见过,求真理

public static string FileUpAndReturnGetNewFileNameRAR(Page p, FileUpload fileUpload, string ver)

{//根据上传页面,上传控件,语言,返回上传后新文件的名称

string newfilename = "";

if (fileUpload.HasFile)

{

string fileExt =

System.IO.Path.GetExtension(fileUpload.FileName);

try

{

newfilename = ver + "_" + GetNewFileName(fileUpload.FileName.ToString()).ToLower();

if (File.Exists(p.Server.MapPath("~/Uploads/" + newfilename)) == false)

{

fileUpload.SaveAs(p.Server.MapPath("~/Uploads/" + newfilename));

}

else

{

//newfilename = ver + "_" + GetNewFileName(fileUpload.FileName.ToString()).ToLower();

//fileUpload.SaveAs(p.Server.MapPath("~/Uploads/" + newfilename));

FunctionClass.ErrorMsg(p, "该文件已经存在!");

}

}

catch (Exception ex)

{

FunctionClass.ErrorMsg(p.Page, "错误:: " + ex.Message.ToString());

}

}

return newfilename;

}

public static string GetNewFileName(string FileName)

{//跟据文伯名产生一个由时间+随机数组成的一个新的文件名

string newfilename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString()

+ DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString()

+ DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString()

+ DateTime.Now.Millisecond.ToString()

//+ rand.Next(1000).ToString()

+ FileName.Substring(FileName.LastIndexOf("."), FileName.Length - FileName.LastIndexOf("."));

return newfilename;

}

需要几分钟?电脑绝对有毛病。

电脑太卡了!