专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > J#

对于FileUpload.Postedload的用法

发布时间:2011-06-24 19:02:14 文章来源:www.iduyao.cn 采编人员:星星草
关于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分可用分!
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: