扩展 asp:controlParameter 以与 FileUpload 控件一起使用

Extending asp:controlParameter for use with FileUpload control

提前致谢。

是否可以在 objectDatasource 控件中扩展 asp:controlParameter 控件以容纳 asp:fileUpload 控件和 return 发布文件的 base64 字符串。

例如我希望能够做到这一点(要注意的关键区域是插入参数):

<asp:listview runat="server" datasourceID="objDS">
 <insertTemplate>
  <asp:fileupload id="fu" runat="server" />
  <asp:button id="submit" runat="server" text="Upload" commandName="INSERT" />
 </insertTemplate>
</asp:listview>

<asp:objectDatasource id="objDS" runat="server" ...>
 <insertParameters>
  <asp:fileuploadControlParameter controlID="fu" type="string" name="base64" />
 </insertParameters>
</asp:objectDatasource>

很明显我一直在以错误的方式处理这个问题,我只是扩展了 asp:fileupload 控件,它允许我将 base64 的新 属性 绑定到现有的 [=13] =]控制objectDatasource.

Public Class fupload
    Inherits FileUpload

    Public ReadOnly Property base64 As String
        Get
            Return encodeBase64()
        End Get
    End Property

    Public Function encodeBase64() As String
        Dim iLen As Integer = MyBase.PostedFile.ContentLength
        Dim btArr As Byte() = New Byte(iLen - 1) {}
        MyBase.PostedFile.InputStream.Read(btArr, 0, iLen)
        Dim b64Str As String = String.Format("data:{0};base64,{1}",
                                             MyBase.PostedFile.ContentType,
                                             Convert.ToBase64String(btArr))
        Return b64Str
    End Function
End Class

用法示例:

<asp:listview runat="server" datasourceID="objDS">
 <insertTemplate>
  <asp:fileupload id="fu" runat="server" base64='<%# bind("base64")' />
  <asp:button id="submit" runat="server" text="Upload" commandName="INSERT" />
 </insertTemplate>
</asp:listview>

<asp:objectDatasource id="objDS" runat="server" ...>
 <insertParameters>
  <asp:Parameter type="string" name="base64" />
 </insertParameters>
</asp:objectDatasource>