提前致谢。
是否可以在objectDatasource控件中扩展asp:controlParameter
控件以容纳asp:fileUpload
控件并返回已发布文件的base64字符串。
例如我希望能够这样做(要注意的关键区域是insert参数):
<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>
答案 0 :(得分:0)
很明显,我一直在以错误的方式接近这一点,我只是扩展了asp:fileupload
控件,允许我将base64的新属性绑定到现有{ {1}}控制asp:parameter
。
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