我有一个 AsyncFileUpload 控件:
<asp:AsyncFileUpload ID="venfileupld" runat="server" OnUploadedComplete="ProcessUpload" />
在其OnUploadedComplete
事件中,我正在编写此代码:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string name = venfileupld.FileName.ToString();
string filepath = "upload_excel/" + name;
venfileupld.SaveAs(Server.MapPath(name));
}
现在我必须阅读上传文件的内容......我有一个功能:
public void writetodb(string filename)
{
string[] str;
string vcode = "";
string pswd = "";
string vname = "";
StreamReader sr = new StreamReader(filename);
string line="";
while ((line = sr.ReadLine()) != null)
{
str = line.Split(new char[] { ',' });
vcode = str[0];
pswd = str[1];
vname = str[2];
insertdataintosql(vcode, pswd, vname);
}
lblmsg4.Text = "Data Inserted Sucessfully";
}
现在我的查询是如何让上传的文件传递给这个函数?
更新
我已经这样做了:
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string name = venfileupld.FileName.ToString();
string filepath = "upload_excel/" + name;
venfileupld.SaveAs(Server.MapPath(name));
string filename = System.IO.Path.GetFileName(e.FileName);
writetodb(filepath);
}
但出现错误...找不到文件