0

メソッドのパラメーターの 1 つとして HttpPostedFiles のリストを期待する電子メールを送信するための C# クラスを使用しています (電子メールへのファイル添付用)。プログラムで電子メールに添付したいファイルが (ファイル システム上に) あり、このクラスを使用してそれを実行しています。私の問題は(私が思うに)以下のコードにあります:

var constructorInfo = typeof(HttpPostedFile).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0];    
HttpPostedFile postedFile = (HttpPostedFile)constructorInfo.Invoke(new object[] { pathString + "Policy_Assoc_home_computer_V8.pdf", "application/pdf", httpStream });

httpStreamタイプであるはずHttpInputStreamです。そのようなものをインスタンス化する方法がわかりません。私は次のことを試しました:

string pathString = Server.MapPath("~/Policy/");
                FileStream stream = new FileStream(pathString + "Policy_Assoc_home_computer_V8.pdf", FileMode.Open);
                Assembly systemWebAssembly = typeof(HttpPostedFile).Assembly;
                Type typeHttpRawUploadedContent = systemWebAssembly.GetType("System.Web.HttpRawUploadedContent");
                Type typeHttpInputStream = systemWebAssembly.GetType("System.Web.HttpInputStream");
                Type[] uploadedParams = { typeof(int), typeof(int) };
                Type[] streamParams = { typeHttpRawUploadedContent, typeof(int), typeof(int) };
                object uploadedContent = typeHttpRawUploadedContent
                    .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, uploadedParams, null)
                    .Invoke(new object[] { stream.Length, stream.Length });
                object httpStream = (Stream)typeHttpInputStream
                    .GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, streamParams, null)
                    .Invoke(new object[] { uploadedContent, 0, stream.Length });

しかし、インスタンス化する行でエラーがスローされますuploadedContent:

object of type System.Int64 cannot be converted to System.Int32

どうすればいいですか?

4

0 に答える 0