vb.net ajax上传文件,VB.net FileUpload using Ajaxcall

Can be accomplished by following the instructions at this link: http://www.binaryintellect.net/articles/f2a2f1ee-e18a-416b-893e-883c800f83f4.aspx

"Instead of making a full page postback you can use jQuery to make an Ajax call to the server and POST the selected files to a generic handler (.ashx). The generic handler can then save the files to a specified folder. The remainder of this post shows how this can be accomplished."

$(document).ready(function () {

$("#Button1").click(function (evt) {

var fileUpload = $("#FileUpload1").get(0);

var files = fileUpload.files;

var data = new FormData();

for (var i = 0; i < files.length; i++) {

data.append(files[i].name, files[i]);

}

var options = {};

options.url = "FileUploadHandler.ashx";

options.type = "POST";

options.data = data;

options.contentType = false;

options.processData = false;

options.success = function (result) { alert(result); };

options.error = function (err) { alert(err.statusText); };

$.ajax(options);

evt.preventDefault();

});

});

Then in your Handler file, you can do something like this to save the POSTed files to your server.

namespace jQueryFileUploadDemo

{

public class FileUploadHandler : IHttpHandler

{

public void ProcessRequest(HttpContext context)

{

if (context.Request.Files.Count > 0)

{

HttpFileCollection files = context.Request.Files;

for (int i = 0; i < files.Count;i++ )

{

HttpPostedFile file = files[i];

string fname = context.Server.MapPath("~/uploads/" + file.FileName);

file.SaveAs(fname);

}

}

context.Response.ContentType = "text/plain";

context.Response.Write("File(s) Uploaded Successfully!");

}

public bool IsReusable

{

get

{

return false;

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在VB.NET中快速读取Excel上文件中的值,您可以使用以下步骤: 1. 在ASP.NET Web应用程序中创建一个FileUpload控件,允许用户上Excel文件。例如: ```vb.net <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="上" OnClick="Button1_Click" /> ``` 2. 在Button1_Click事件处理程序中,使用Microsoft.Office.Interop.Excel库打开Excel文件并读取数据。例如: ```vb.net Protected Sub Button1_Click(sender As Object, e As EventArgs) '获取上的Excel文件 Dim filePath As String = Server.MapPath(FileUpload1.FileName) '创建Excel应用程序对象 Dim oExcel As New Excel.Application '打开Excel文件 Dim oWorkbook As Excel.Workbook = oExcel.Workbooks.Open(filePath) '获取第一个工作表 Dim oWorksheet As Excel.Worksheet = oWorkbook.Sheets(1) '获取工作表中的数据范围 Dim oRange As Excel.Range = oWorksheet.UsedRange '遍历数据范围,读取每个单元格的值 For i As Integer = 1 To oRange.Rows.Count For j As Integer = 1 To oRange.Columns.Count Dim cellValue As String = oRange.Cells(i, j).Value2.ToString() '对读取到的值进行处理,例如输出到控制台 Console.WriteLine(cellValue) Next Next '关闭Excel文件和应用程序 oWorkbook.Close() oExcel.Quit() End Sub ``` 在上面的代码中,我们首先获取上的Excel文件的路径,然后使用Excel对象模型打开Excel文件并读取数据。读取数据的步骤与前面的示例相同,遍历数据范围并读取每个单元格的值。最后,我们关闭Excel文件和应用程序。 希望这个示例可以帮助您快速读取Excel上文件中的值!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值