文件保存路径 mPath = Server.MapPath("E:\毕业设计\websites\test");
string filePath = "", fileExName = "", mFileName, mPath;
if ("" != fileUp.PostedFile.FileName)
{
filePath = fileUp.PostedFile.FileName;//取得文件路径
fileExName = filePath.Substring(filePath.LastIndexOf(".") + 1);//取得文件扩展名
try
{
mPath = Server.MapPath("E:\毕业设计\websites\test");
mFileName = filePath.Substring(filePath.LastIndexOf("\") + 1);
fileUp.PostedFile.SaveAs(mPath + mFileName);
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
其中mPath = Server.MapPath("E:\毕业设计\websites\test");
这个里面的路径应该怎么写,这样写好像是错误的,不好获取; String
[解决办法]
mPath = @"E:\毕业设计\websites\test";
[解决办法]
同意楼上在前面加@的说法~
另外楼主在文件夹目录test和文件名mFileName中间有没有加“\”啊...
貌似好像是有的...
[解决办法]
Path.GetExtension(fileName)扩展名,Server.MapPath("~/XXX/XX.X");
[解决办法]
Server.MapPath("~/网站根目录");
这里应该是相对路径。
[解决办法]
Server.MapPath(text)
[解决办法]
/// <summary>
/// 文件上传 路径upload/ 自动重命名
/// </summary>
/// <param name="page">Page或this</param>
/// <param name="f">上传控件FileUpload</param>
/// <returns>文件路径</returns>
public static string fileupload(Page page, FileUpload f)
{
try
{
string name = DateTime.Now.ToString("yyyyMMddhhmmss");
Random ran = new Random(DateTime.Now.Second);
name += ran.Next(10000);
string filename = f.FileName;
string path = page.Server.MapPath("~/upload/" + filename);
if (System.IO.File.Exists(path))
{
System.IO.Directory.CreateDirectory(page.Server.MapPath("~/upload/") + name);
f.SaveAs(page.Server.MapPath(@"~\upload") + name + @"" + filename);
return "upload/" + name + @"/" + filename;
}
f.SaveAs(page.Server.MapPath(@"~\upload") + filename);
return "upload/" + filename;
}
catch (Exception tt)
{
throw new Exception(tt.Message);
}
}