0

我想使用 . 将多个文件上传到 SQL 数据库中AjaxFileUpload。我有一种上传单个文件的方法;在 aspx 页面中:

<asp:FileUpload ID="file_Image" runat="server"/>

在 aspx.cs 页面中:

protected void UploadFile(object sender, EventArgs e)
{
    FileUpload FileUpload1 = file_Image;

    // Read the file and convert it to Byte Array
    string filePath = file_Image.PostedFile.FileName;
    string filename = Path.GetFileName(filePath);

    if (FileUpload1.HasFile && FileUpload1.PostedFile != null)
    {
        Stream fs = file_Image.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(fs);
        Byte[] bytes = br.ReadBytes((Int32)fs.Length);}}

但是,我如何使用类似的东西AjaxFileUpload,甚至可以从 Ajax 控件流式传输这样的图像数据?感谢一百万分享您的知识!

4

1 回答 1

1

[参考新AjaxFileUpload控件AjaxToolKit][1] http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

这个新的 AjaxFileUpload 控件支持一次上传多个文件。但 IE10 或 Chrome 最新版本支持此功能有一些限制。

这个很靠谱,我在用这个。

将 AjaxFileUpload 文件内容转换为 sql varbinary 数组的简单方法:

protected void AjaxFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
byte[] image = e.GetContents();
}
于 2013-03-08T19:50:13.843 回答