asp.net 文件上传报错

问题:IE8、部分IE7可正常上传,但部分IE7和IE六上传失败。虚拟路径无效。

解决方案:

 private void UpLoad()
    {
        string filePath = "";

        //**********************************************************问题1**********************************************************

        //filePath = this.FileUpload1.PostedFile.FileName;//之前的写法,IE6、7报错

        HttpPostedFile PostFile = this.FileUpload1.PostedFile;//上传的文件对象(正常)
        filePath = System.IO.Path.GetFileName(PostFile.FileName); //文件名(正常)
        DirectoryInfo upDir = new DirectoryInfo(Server.MapPath("../SystemManage/DocumentManage"));
        if (!upDir.Exists)
        {
            upDir.Create();
        }
        int m = filePath.LastIndexOf("."); //取得文件名中最后一个"."的索引
        string newext = filePath.Substring(m);

        int ContentLength = this.FileUpload1.PostedFile.ContentLength;
        int UploadedLength = 0;

        if (FileUpload1.FileContent.Length != 0)
        {
            DateTime now = DateTime.Now; //获取系统时间
            string path1 = (filePath.Split('.')[0] + DateTime.Now.ToString("yyyMMddHHmmss").Trim() + newext).Trim();
            string path = this.Server.MapPath(@"DocumentManage/" + Server.HtmlEncode(path1));
            try
            {

                FileUpload1.PostedFile.SaveAs(path); //上传大文件发布以后报错

            }
            catch (Exception ex)
            { }

        }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值