protected string upload(object img)
    {
        string[] imgList = img.ToString().Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
        foreach (var item in imgList)
        {
            HttpPostedFile postedFile;
            postedFile.SaveAs(Server.MapPath("temp") + "\\" + item);
        }
        return "true";
    }img是前台传过来的多文件
imgList里存储的是文件名数组
怎么使用PostFile上传?

解决方案 »

  1.   

    HttpPostedFile postedFile;
                postedFile.SaveAs(Server.MapPath("temp") + "\\" + item);
    你这段代码会出现未将对象应用到实例。SaveAs不是静态方法。
    String TempFileName;
     HttpFileCollection MyFileCollection = imgList;
     
     for (int Loop1 = 0; Loop1 < MyFileCollection.Count; Loop1++)
     {
            TempFileName = Server.MapPath("temp") + "\\"+ Loop1.ToString();
        
        MyFileCollection[Loop1].SaveAs(TempFileName);
     }
    return "true";
      

  2.   


    跟这没关系吧
    HttpPostedFile postedFile;这样写报的是为实例化的错