首先是aspx页面 <asp:FileUpload ID="FUploadAttachMent" runat="server" Height="25px" Width="665px" /> <asp:Button ID="Button1" runat="server" Text="上传" οnclick="BtnUpload_Click" /> 然后是cs页面 protected void BtnUpload_Click(object sender, EventArgs e) { string str=this.FileUpload(); MessageBox(this.page,str); } #region FileUpload 上传文件(外層判斷) protected string FileUpload(string InputData) { string inputPath = ""; string str3 = ""; try { inputPath = "//empr/Data/"; str3 = FileUploadExe(inputPath); } catch (Exception ex) { MessageBox.Show(Page, ex.Message); } return str3; } protected string FileUploadExe(string inputPath) { string inputTotalPath = ""; string str3 = ""; if (this.FUploadAttachMent.HasFile) { inputTotalPath = inputPath + this.FUploadAttachMent.FileName.ToString(); if (Files.IsDirectoryExists(inputPath)) { this.IsExistsUp(inputTotalPath, inputPath, this.FUploadAttachMent.FileName); //三个参数,第一个参数内容就是第二个加第三个,第二个是上传地址,第三个是上传的文件名 str3 = "文件上傳成功!"; } else { Files.CreateDirectory(inputPath);//不存在则创建目录 this.IsExistsUp(inputTotalPath, inputPath, this.FUploadAttachMent.FileName); str3 = "文件上傳成功!"; } } return str3; } #region IsExistsUp 檢測文件並上傳(裏層上傳) p