FileUpload路徑

Claire_ljy發表於2020-04-04
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.";
        }
    }

轉載於:https://www.cnblogs.com/MySpace/archive/2009/11/10/1599826.html

相關文章