用FILE上传图片,在本地正常,到服务器后提示为空.于是测试:if (fileLogo.PostedFile == null)
        {
            Response.Write("no");
        }
        else
        {
            Response.Write(fileLogo.PostedFile.FileName);
        }结果:
在本地为:C:\Documents and Settings\Administrator\桌面\noImg.jpg 
在服务器上的测试为:no说明在本地判断不为空,在服务器端为NULL.哪位大虾知道是什么原因,可以给小弟解释一下么?

解决方案 »

  1.   

    楼上你好
    我也想到过是否是文件夹权限问题
    可是为什么在服务器上面fileLogo.PostedFile 判断为空呢?
      

  2.   

    说明在本地判断不为空,在服务器端为NULL.....
    路径和文件怎么存储的?
      

  3.   

    string myDirectory = "~/XXX/YYY/"; //你保存服务端的目录
    string myPathAndName = myDirectory + myFileUpload.FileName; //路径加文件名
    FileUpload1.SaveAs(Server.MapPath(myPathAndName)); //将文件上传
      

  4.   

    楼上有点错!!应该是这样:
    string myDirectory = "~/XXX/YYY/"; //你保存服务端的目录 
    string myPathAndName = myDirectory + FileUpload1.FileName; //路径加文件名 
    FileUpload1.SaveAs(Server.MapPath(myPathAndName)); //将文件上传 
      

  5.   

    谢谢大家的关注
            if (fileLogo.PostedFile != null)
            {
                string contentName = fileLogo.PostedFile.ContentType;
                if (contentName == "image/bmp" || contentName == "image/gif" || contentName == "image/pjpeg")
                {
                    string path = Server.MapPath("../bbs/images/" + logoName);
                    Response.Write(path);
                    try
                    {
                        fileLogo.PostedFile.SaveAs(path);
                        isok = true;
                    }
                    catch
                    {
                        isok = false;
                    }
                }这是上传文件的代码
    在第一行判断的时候就没有通过,判断fileLogo.PostedFile为空
      

  6.   

    另,在网站中用到了类似于FCKEDIT那样的文本编辑控件,也获取不到值.在本地能够获取得到,会不会是服务器的问题呢?
      

  7.   

     string path = Server.MapPath("../bbs/images/" + logoName);
    把上面的../bbs/images/换成~/bbs/images/试一下
      

  8.   

    string path = Server.MapPath("~/bbs/images/" + logoName);
    感觉最有可能的是路径问题
      

  9.   

    大家好,问题还没有解决
    我做了一个测试用的页面上传到服务器
    ASPX:<body>
        <form id="form1" runat="server">
        <div>
        <input type="file" runat="server" id="fileLogo" />
        <asp:Button runat="server" ID="btnRead" Text="Read" onclick="btnRead_Click" />ASPX.CS:protected void btnRead_Click(object sender, EventArgs e)
        {
            string name = fileLogo.Value;
            string type = fileLogo.PostedFile.ContentType;
            Response.Write(name);
            Response.Write("<br/>");
            Response.Write(type);
        }
    这里根本就没有要保存文件的代码,只是想要读取到文件的一些属性
    在本地运行正常
    但是上传服务器后报错:
    Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: 
    Line 19:     {
    Line 20:         string name = fileLogo.Value;
    Line 21:         string type = fileLogo.PostedFile.ContentType;
    Line 22:         Response.Write(name);
    Line 23:         Response.Write("<br/>");
     Source File: e:\hosting\wwwroot\fengbaoyan_com\htdocs\AdminNews\testFile.aspx.cs    Line: 21 Stack Trace: 
    [NullReferenceException: Object reference not set to an instance of an object.]
       AdminNews_testFile.btnRead_Click(Object sender, EventArgs e) in e:\hosting\wwwroot\fengbaoyan_com\htdocs\AdminNews\testFile.aspx.cs:21
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746 麻烦大家再帮忙看一下,谢谢.
      

  10.   

    用fileupload 试试.代码没问题.我写过,在虚拟空间运行很好.可能与其他代码有关.
      

  11.   

    换成FILEUPLOAD后也是一样的问题,只要访问控件的POSTEDFILE值就引发未将对象实例化的错误,可是哪个值为空呢.想在本地测试,但程序在本地运行正常.
      

  12.   

    Line 20:        string name = this.fileLogo.Value; 
    Line 21:        string type = this.fileLogo.PostedFile.ContentType; 
    文件上传:路径:如果是主站而不是虚拟目录可用../方式
    否则用~/