当前位置: 代码迷 >> J# >> 关于FileUpload.Postedload的用法解决办法
  详细解决方案

关于FileUpload.Postedload的用法解决办法

热度:8774   发布时间:2013-02-25 00:00:00.0
关于FileUpload.Postedload的用法
大侠们,小弟写了个文件上传的程序,可是运行总是报错,错误提示如下 
非静态字段、方法或属性“System.Web.UI.WebControls.FileUpload.PostedFile.get”要求对象引用
程序如下:
 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.IO"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat ="server" >
    void UploadButton_Click(object sender, EventArgs e)
    {
        string savePath = @"f:\";
        if (!Directory.Exists(savePath))
        {
            string msg = "<h1>Upload path doesn't exist:{0}</h1>";
            Response.Write(String.Format(msg, savePath));
            Response.End();
        }

        if (FileUpload.PostedFile !=null )
        {
            string fileName = Path.GetFileName(FileUpload.Value);
            savePath += fileName;
            FileUpload.PostedFile.SaveAs(savePath);
            UploadStatusLabel.InnerText = "File saved as :"+savePath ;
        }
        else
        {
            UploadStatusLabel.InnerText = "NO file specified.";
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title>file upload</title>
</head>
<body>
    <form id="form1" runat="server">
    <h3>Select a picture to upload:</h3>.
    <hr/>
    <b>select a  picture to upload:</b><br />
    <input type="file" id="FileUploadButton" runat ="server"  />
    <br/><br />
    <input runat ="server" id="UploadButton" type="submit" 
    value="Upload" oneserverclick="UploadButton_Click"/>
    <hr />
    <span runat ="server" id="UploadStatusLabel" />
    <div>
    
    </div>
    
    </form>
</body>
</html>
请大家指教下谢谢
------解决方案--------------------------------------------------------
每天回帖即可获得10分可用分!
  相关解决方案