How to instantiate a HttpPostedFile

前端 未结 2 897
你的背包
你的背包 2020-12-09 11:11

I\'m trying to communicate with a system which I have no control over, however one of its methods takes in a HttpPostedFile were in my code I have a byte array. Does anybody

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 11:41

    you can try

     var constructorInfo = typeof(HttpPostedFile).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];
     var obj = (HttpPostedFile)constructorInfo
               .Invoke(new object[] { "filename", "image/jpeg", null });
    

    obj would of type HttpPostedFile .I'm setting the last parameter to null but it has to be a HttpInputStream though.

提交回复
热议问题