FileUpload

只能用绝对路径,真BT...

---------------get root function begin-------------------

public static string GetRootPath()
    {
        string AppPath = "";
        HttpContext HttpCurrent = HttpContext.Current;
        if (HttpCurrent != null)
        {
            AppPath = HttpCurrent.Server.MapPath("~");
        }
        else
        {
            AppPath = AppDomain.CurrentDomain.BaseDirectory;
            if (Regex.Match(AppPath, @"\\$", RegexOptions.Compiled).Success)
                AppPath = AppPath.Substring(0, AppPath.Length - 1);
        }
        return AppPath;
    }

---------------get root function end-------------------

 

     if (FileUpload1.HasFile)
        {
            string filePath = GetRootPath();
            string fileName = DateTime.Now.ToFileTime().ToString();--根据时间生成文件名称
            string fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();--取得文件后缀名
            fullFileName = fileName + fileExtension;
            fullPath = filePath + "\\student\\photo\\" + fileName + fileExtension;
            FileUpload1.SaveAs(fullPath);
        }

posted on 2008-09-10 16:44  Joe Hou  阅读(253)  评论(0编辑  收藏  举报