日期:2014-05-17  浏览次数:20403 次

文件保存路径 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