对于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分可用分!
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
关于FileUpload.Postedload的用法
大侠们,小弟写了个文件上传的程序,可是运行总是报错,错误提示如下
非静态字段、方法或属性“Sys...
-
我这样的技术找工作真的很难吗?【比北大青鸟出来的和应届毕业生都不如】
我本科的,只做过一个网站www_gzfesco_com_cn-------》这...
-
Visual J# 断点调试和vc有什么区别?
如题
------解决方案--------------------
帮顶,学习。
------解决方案--------------------...
-
j# form中 放了pictureBox1控件,label1控件放在pictureBox1上面,如何能把label1背景设置为透明呢
请教各位了。
------解决方案-...
-
问一下关于silverlight 的问题 大家别扔我啊 就是有点搞不清楚!
一直觉的silverlight 做出来的东西很炫
也知道它是微软开发的...
-
根据年、月、周、求本月的起始日和结束日!
根据年、月、周、求本月的起始日和结束日!
根据年、月、周、求本月的起始日和结束日!
...
-
TextBox Readonly 后,前台赋值,后台无法取得资料
请教如何处理,最好不要用隐藏控件解决,在线等回复
------解决方案----------------...
-
javascript
$(document).ready(function() {
$("#CheckAll").click(function() {
if ($(this).attr("checked") ==...
-
winform DataGridView根据光标位置设置所在行的背景颜色
如题。。。
------解决方案--------------------
C# code
private voi...
-
如何防止多个title出现
是这样的,为了实现SEO,我用的母板,下面用了一个content但是运行时页面出现了两对<title>标签,我只想显示conte...