Frankwangyifang

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
string xlsPath = this.FileUpload1.PostedFile.FileName;
string xlsPath = Server.MapPath("~/Excel/客户需求表.xls");

两者区别:
前者是物理路径,后者是服务器路径.
 
 
FileUpload ful = new FileUpload();

        ful.FileName;   //文件件
        ful.PostedFile.ContentLength;//文件大小,单位 B,除以 1024得到 K
        ful.PostedFile.FileName;//完全路径



protected void Button1_Click(object sender, EventArgs e)
    {
        Boolean fileOK = false;
        String path = Server.MapPath("~/UploadedImages/");
        if (FileUpload1.HasFile)
        {
            String fileExtension =
                System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
            String[] allowedExtensions =
                { ".gif", ".png", ".jpeg", ".jpg" };
            for (int i = 0; i < allowedExtensions.Length; i++)
            {
                if (fileExtension == allowedExtensions)
                {
                    fileOK = true;
                }
            }
        }
        if (fileOK)
        {
            try
            {
                FileUpload1.PostedFile.SaveAs(path
                    + FileUpload1.FileName);
                Label1.Text = "File uploaded!";
            }
            catch (Exception ex)
            {
                Label1.Text = "File could not be uploaded.";
            }
        }
        else
        {
            Label1.Text = "Cannot accept files of this type.";
        }
    }
posted on 2009-11-10 13:38  Frankwangyifang  阅读(600)  评论(0编辑  收藏  举报