FileUpload中怎样设置上传文件的相对路径
if(FileUpload1.HasFile){stringfileContentType=FileUpload1.PostedFile.ContentType;stri...
if (FileUpload1.HasFile)
{
string fileContentType = FileUpload1.PostedFile.ContentType;
string name = FileUpload1.PostedFile.FileName;// 客户端文件路径
FileInfo file = new FileInfo(name);
string fileName = file.Name; // 文件名称
string webFilePath = Server.MapPath(fileName); // 服务器端文件路径 10485760
string strUserExtName = name.Substring(name.LastIndexOf("."));
if (FileUpload1.PostedFile.ContentLength < 10485760)
{
try
{
if (strUserExtName != ".exe" && strUserExtName != ".dll")
{
string path = Server.MapPath("../file/" + fileName);
FileUpload1.SaveAs(path);
teacherplanning.FilePath = path;
teacherplanning.FileSize = (this.FileUpload1.PostedFile.ContentLength / 1024) + 1;
teacherplanning.FileType = this.FileUpload1.FileName.Remove(0, this.FileUpload1.FileName.LastIndexOf('.') + 1);
}
}
}这段代码,无论我怎样改,得到的都是带有盘符的绝对路径,怎样得到上传文件的相对路径啊?也就是我要将 string path = Server.MapPath("../file/" + fileName); 转换为绝对路径。 展开
{
string fileContentType = FileUpload1.PostedFile.ContentType;
string name = FileUpload1.PostedFile.FileName;// 客户端文件路径
FileInfo file = new FileInfo(name);
string fileName = file.Name; // 文件名称
string webFilePath = Server.MapPath(fileName); // 服务器端文件路径 10485760
string strUserExtName = name.Substring(name.LastIndexOf("."));
if (FileUpload1.PostedFile.ContentLength < 10485760)
{
try
{
if (strUserExtName != ".exe" && strUserExtName != ".dll")
{
string path = Server.MapPath("../file/" + fileName);
FileUpload1.SaveAs(path);
teacherplanning.FilePath = path;
teacherplanning.FileSize = (this.FileUpload1.PostedFile.ContentLength / 1024) + 1;
teacherplanning.FileType = this.FileUpload1.FileName.Remove(0, this.FileUpload1.FileName.LastIndexOf('.') + 1);
}
}
}这段代码,无论我怎样改,得到的都是带有盘符的绝对路径,怎样得到上传文件的相对路径啊?也就是我要将 string path = Server.MapPath("../file/" + fileName); 转换为绝对路径。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询