不用密码,但上传到的服务器相应文件夹需要有写入权限才行
下面是上传excel的
File1是 fileupload
string XLS_Path = "";
string XLS_Name = MakeFileName();
string fileExtName = "";
if (File1.PostedFile.ContentLength > 0)
{
try
{
fileExtName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("."));
string FileType = File1.PostedFile.ContentType;
int FileSize = File1.PostedFile.ContentLength;
if (FileSize < 10 || FileSize > 20000000)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "a", "");
return;
}
if ((FileType.ToLower() != "application/vnd.ms-excel" || fileExtName.ToLower() != ".xls") && (FileType.ToLower() != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || fileExtName.ToLower() != ".xlsx"))
{
this.ClientScript.RegisterStartupScript(this.GetType(), "a", "");
return;
}
if (fileExtName.Length < 1)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "a", "");
return;
}
File1.PostedFile.SaveAs(Server.MapPath("../uploadexcel/") + XLS_Name + fileExtName);
XLS_Path = Server.MapPath("../uploadexcel/") + XLS_Name + fileExtName;
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
else
{
this.ClientScript.RegisterStartupScript(this.GetType(), "a", "");
return;
}
有一个叫做fileupload的控件,你可以试试,这里面有个saveas的函数来执行上传操作的,不需要密码,不过需要将你上传的那个目录设置一下777的权限才可以