dim file as HttpPostedfile = Fileup.Postedfile
dim dfile as file
If file.contentlength<>0 then 变量最好不要用file,改一个变量名吧。用myFiledim myFileas HttpPostedfile = Fileup.Postedfile
dim dfile as file
'测试的时候,可先判断是否为空,语法不知道对不对:
if myFile <> nothing then
If myFile.contentlength<>0 then
dim dfile as file
If file.contentlength<>0 then 变量最好不要用file,改一个变量名吧。用myFiledim myFileas HttpPostedfile = Fileup.Postedfile
dim dfile as file
'测试的时候,可先判断是否为空,语法不知道对不对:
if myFile <> nothing then
If myFile.contentlength<>0 then
[NullReferenceException: 未将对象引用设置到对象的实例。]
xingzhengcf.gongcheng_xuanzhe.datarefresh() in c:\inetpub\wwwroot\xzcfys\gongcheng_xuanzhe.aspx.vb:48
xingzhengcf.gongcheng_xuanzhe.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\xzcfys\gongcheng_xuanzhe.aspx.vb:31
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
上传控件事客户端的控件,你点提交后file.value为空,所以出错有什么解决办法代码在本地怎么不出错?
<%@ page Language="C#" debug="true" %>
<html>
<head>
<title>上传文件 , http://www.chinabs.net </title>
<script language="C#" runat="server">
//This method is called when the "upload" button id pressed
public void UploadFile(object sender , EventArgs E)
{
//检查上传文件不为空
if(myFile.PostedFile!=null)
{
string nam = myFile.PostedFile.FileName ;
//取得文件名(抱括路径)里最后一个"."的索引
int i= nam.LastIndexOf(".");
//取得文件扩展名
string newext =nam.Substring(i);
//这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
DateTime now = DateTime.Now;
string newname=now.DayOfYear.ToString()+myFile.PostedFile.ContentLength.ToString();
//保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变.
//注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替
myFile.PostedFile.SaveAs(Server.MapPath("\\upload\\"+newname+newext));
//得到这个文件的相关属性:文件名,文件类型,文件大小
fname.Text=myFile.PostedFile.FileName;
fenc.Text=myFile.PostedFile.ContentType ;
fsize.Text=myFile.PostedFile.ContentLength.ToString();
}
}</script>
但是觉得奇怪的是没有加encType属性说明本地也能通过的