string strFileName;
strFileName=this.upPIC.PostedFile.FileName;
FileStream fs = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.Read);以上代码在本机上运行正常,但是传到服务器中运行却提示:
Could not find a part of the path "C:\Documents and Settings\Administrator\My Documents\My Pictures\1.gif". 可能是由于上面的代码只读取服务器上的C:\Documents and Settings\Administrator\My Documents\My Pictures\1.gif文件而非读取客户端上的文件!如何解决!?

解决方案 »

  1.   

    是asp.net程序吧?你的程序本来就运行在服务器端,如何能读取客户端的文件?在本机测试之所以能运行是因为你的机器是客户机的同时又是服务器。
      

  2.   

    使用绝对路径或者使用<input type=file name=f1 runat=server>来选取路径
      

  3.   

    Sorry,看错了,还以为楼主要直接读取客户端的文件,如果你要直接读取用户上传的文件中的内容而不用保存后再读取,可以这样,这是前段时间正好写过的一个例子的代码:void UploadFile(object src,EventArgs e){
    HttpPostedFile pf=fu.PostedFile;
    if(pf==null||pf.ContentLength==0)
    Response.Write("&Atilde;&raquo;&Oacute;&ETH;&Icirc;&Auml;&frac14;&thorn;±&raquo;&Eacute;&Iuml;&acute;&laquo;&pound;&iexcl;");
    else{
    int fl=pf.ContentLength;
    MemoryStream ms=new MemoryStream();
    byte[] fb=new byte[fl];
    Stream fs=pf.InputStream;
    fs.Read(fb,0,fl);
    string s=Encoding.GetEncoding("gb2312").GetString(fb);
    lb_file.Text=s;
    }
    }