上传文件(文件另存为,有指定的路径)

private SellerInfo uploadFile()     {         SellerInfo sellerInfo = new SellerInfo();

        String filePath = Server.MapPath("~/" + SellerReservatBL.SELLER_INFO_FILE);

        sellerInfo.ID = Request.QueryString["ID"];         sellerInfo.Sup_No = this.Sup_No.Text;         sellerInfo.Site_No = this.DlistStore.Text;         sellerInfo.EntryDate = this.ReservationDate.Text;         sellerInfo.SellerName = this.SellerName.Text;         sellerInfo.CardId = this.CardId.Text;         sellerInfo.Phone = this.Phone.Text;         sellerInfo.Brand = this.Brand.Text;         sellerInfo.OnlinePurchase = this.OnlinePurchase.Text;         sellerInfo.BussinessName = this.BussinessName.Text;         sellerInfo.BussinessPhone = this.BussinessPhone.Text;

        if (string.IsNullOrEmpty(this.FileUrl.Text))         {             if (!Directory.Exists(filePath + "/" + GetLoginUserNo()))             {                 Directory.CreateDirectory(filePath + "/" + GetLoginUserNo());             }

            if (string.IsNullOrEmpty(sellerInfo.ID))             {                 sellerInfo.ID = sellerBL.GetNextID("SellerInfo", "ID");             }

            HttpFileCollection hfc = Request.Files;             for (int i = 0; i < hfc.Count; i++)             {                 HttpPostedFile hpf = hfc[i];                 if (hpf.ContentLength > 0)                 {                     sellerInfo.AdjunctURL = filePath + "/" + GetLoginUserNo() + "/" + sellerInfo.Sup_No + "_" + sellerInfo.Site_No + "_" + sellerInfo.ID + ".rar";                 }             }

            for (int i = 0; i < hfc.Count; i++)             {                 HttpPostedFile hpf = hfc[i];                 if (hpf.ContentLength > 0)                 {                     hpf.SaveAs(sellerInfo.AdjunctURL);                 }             }         }         else         {             sellerInfo.AdjunctURL = this.FileUrl.Text;         }

        return sellerInfo;     }

原文地址:https://www.cnblogs.com/Carri/p/5405144.html