HtmlInputFile

 /// <summary>
       /// 把客户端路径转化成服务端的路径
       /// </summary>
       /// <param name="savePath">保存的地址可空</param>
       /// <param name="inputfile">上传的HtmlInputFile控件</param>
       /// <param name="allowedFormats">null</param>
       /// <returns></returns>
       public static string UploadFile(string savePath, HtmlInputFile inputfile, params string[] allowedFormats)
       {
           int num1 = 0;
           bool flag1 = false;
           if (inputfile.PostedFile.ContentLength <= 0)
           {
               throw new Exception("/u4e0a/u4f20/u6587/u4ef6/u4e3a/u7a7a/u3002");
           }
           string text1 = inputfile.PostedFile.FileName;
           num1 = Math.Max(text1.LastIndexOf(@"/"), 0);
           int num2 = text1.LastIndexOf(".");
           string text2 = text1.Substring(num2).ToLower();
           if (string.IsNullOrEmpty(savePath))
           {
               string text3 = ConfigurationManager.AppSettings.Get("upload");
               string[] textArray1 = new string[5];
               textArray1[0] = inputfile.Page.Server.MapPath(text3);
               textArray1[1] = @"/";
               Guid guid1 = Guid.NewGuid();
               textArray1[2] = guid1.ToString();
               textArray1[3] = ".";
               textArray1[4] = text2;
               savePath = string.Concat(textArray1);
           }
           if (allowedFormats != null)
           {
               string[] textArray2 = allowedFormats;
               for (int num3 = 0; num3 < textArray2.Length; num3++)
               {
                   string text4 = textArray2[num3];
                   if (text2 == text4.ToLower())
                   {
                       flag1 = true;
                       break;
                   }
               }
           }
           else
           {
               flag1 = true;
           }
           if (flag1)
           {
               inputfile.PostedFile.SaveAs(savePath);
               return savePath;
           }
           throw new Exception("/u6587/u4ef6/u683c/u5f0f/u9519/u8bef/uff0c/u8bf7/u9009/u62e9/u6269/u5c55/u540d/u4e3a/uff1a" + string.Join("!", allowedFormats) + "/u7684/u6587/u4ef6/u3002");
       }

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值