后台代码:
bool
fileok
=
false
;
string Attachment = String.Empty;
string path = Server.MapPath( " Upload/Question/ " ); // 定义目标文件夹
string pathinDB = " Upload/Question/ " ;
string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); // 获取文件扩展名
if (FileUpload1.HasFile == true )
{
string[] allowedExtensions ={ ".gif", ".png", ".bmp", ".jpg", ".jpeg", ".doc", ".txt", ".xls", ".pdf" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileok = true;
}
}
}
if (fileok)
{
try
{
Attachment = path + "你自己写的新名字"+ fileExtension;
pathinDB += ”你自己写的新名字“+ fileExtension;
FileUpload1.SaveAs(Attachment);
string strInsert = "";//插入SQL 数据库的语句
getDB.cmdExecute(strInsert);//通过类,写入数据库
}
catch
{
}
}
else
{
}
string Attachment = String.Empty;
string path = Server.MapPath( " Upload/Question/ " ); // 定义目标文件夹
string pathinDB = " Upload/Question/ " ;
string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); // 获取文件扩展名
if (FileUpload1.HasFile == true )
{
string[] allowedExtensions ={ ".gif", ".png", ".bmp", ".jpg", ".jpeg", ".doc", ".txt", ".xls", ".pdf" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileok = true;
}
}
}
if (fileok)
{
try
{
Attachment = path + "你自己写的新名字"+ fileExtension;
pathinDB += ”你自己写的新名字“+ fileExtension;
FileUpload1.SaveAs(Attachment);
string strInsert = "";//插入SQL 数据库的语句
getDB.cmdExecute(strInsert);//通过类,写入数据库
}
catch
{
}
}
else
{
}