protected Boolean uploadfile(FileUpload fup, string cid)//(上传控件名称,以ID作为文件夹名称却确唯一)
{
Boolean fileOK = false; //文件有效标记;
string fp = "upfile/" + cid + "/";
String path = Server.MapPath(fp);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (fup.HasFile) //是否包含文件;
{
String fileExtension = System.IO.Path.GetExtension(fup.FileName).ToLower();
String[] allowedExtensions =
{ ".gif", ".png", ".jpeg", ".jpg", ".doc", ".pdf", ".xls", ".htm", ".html", ".bmp", ".mdb", ".mpp", ".vsd", ".txt", ".bmp", ".ini" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
if (!File.Exists(path + fup.FileName))
{
fileOK = true;
}
}
}
}
if (File.Exists(path + fup.FileName))//文件是否已存在;
{
//this.upokd.Text = "上传失败,文件已存在或者不允许上传此类型的文件。特殊文件请与管理员联系!";
}
else
{
if (fileOK)//文件有效;
{
try
{
//上传成功;
fup.PostedFile.SaveAs(path + fup.FileName);
return true;
}
catch (Exception ex)
{
}
}
else
{
// this.upokd.Text = "上传失败,文件已存在或者不允许上传此类型的文件。特殊文件请与管理员联系!";
}
}
给文件夹加锁
最新推荐文章于 2021-03-15 22:26:48 发布