C#.net 通过后台 上传文件案例

来源:互联网 发布:淘宝新娘饰品 编辑:程序博客网 时间:2024/05/19 19:14

前台:

<asp:FileUpload ID="FileUpload1" runat="server" />


后台cs代码:

 if (HttpContext.Current.Request.Files.Count > 0)

                {
                    HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
                    string savePath;
                    string dir = HttpContext.Current.Request.PhysicalApplicationPath;
                    savePath = dir + "Upload\\DocumentFiles\\";
                    savePath += Path.GetFileName(postedFile.FileName);
                    Session["savePath"] = savePath;

                    //FileName.Text = Path.GetFileName(postedFile.FileName);
                    //LG_BLL.VendorAttachment vendor = new LG_BLL.VendorAttachment();
                    ////vendor.InsertVendors(FileType.Text, FileName.Text, Vendortxt.Text);

                    if (File.Exists(savePath))
                    {
                        File.Delete(savePath);
                    }
                    postedFile.SaveAs(savePath);

                }
0 0