如何在将数据插入数据库之前在gridview中保存Fileupload详细信息 [英] How to save Fileupload details in gridview before inserting data into database
本文介绍了如何在将数据插入数据库之前在gridview中保存Fileupload详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在将文件信息保存到数据库之前,我必须将多个文件上传到网格。这可能吗....?
谢谢。
解决方案
使用两种方式都可以达到这个目的.Fileupload控件是在ASP.net中内置控件。
这是HTML代码。
< pre lang =HTML> < html xmlns = http://www.w3 .org / 1999 / xhtml >
< head runat = server >
< 标题 > < / title >
< script src = jquery.js 类型 = text / javascript > < / < span class =code-leadattribute> script >
< script src = jquery.MultiFile.js type = text / javascript > < / script >
< / head >
< 正文 >
< 表单 id = form1 < span class =code-attribute> runat = server >
< div >
< asp:fileupload < span class =code-attribute> id = FileUpload1 runat = server xmlns:asp = #unknown < span class =code-keyword> / >
< br / >
< asp:fileupload < span class =code-attribute> id = FileUpload2 runat = server xmlns:asp = #unknown < span class =code-keyword> / >
< br / >
< asp:fileupload id = FileUpload3 runat = server xmlns:asp = #unknown / >
< br / >
< asp:fileupload < span class =code-attribute> id = FileUpload4 runat = server xmlns: asp = #unknown / >
< / div >
< asp:button id = btnUpload runat = 服务器 xmlns:asp = #unknown >
onclick =btnUpload_Click
Text = 上传文件/> < br / > < < span class =code-leadattribute> br / >
< / form >
< / body >
< / html >
< / asp:button >
保存代码单击按钮上的文件。
protected void btnUpload_Click( object sender,EventArgs e)
{
HttpFileCollection uploads = Request.Files;
for ( int fileCount = 0 ; fileCount < uploads.Count; fileCount ++)
{
HttpPostedFile uploadedFile = uploads [fileCount];
string fileName = Path.GetFileName(uploadedFile.FileName);
if (uploadedFile.ContentLength > 0 )
{
uploadedFile.SaveAs(Server.MapPath( 〜/ Files /)+ fileName);
lblMessage.Text + = fileName + 已上传< br />;
}
}
}
这里将上传的文件保存到服务器中,在你的情况下你可以提取文件的详细信息并保存到数据库。
希望这个帮助。
谢谢。< br $> b $ b
格式化文本。
[/编辑]
I have to upload multiple files to a grid before I save the file information into database . Is this possible....?
Thanks.
解决方案
Using both ways you can achieve this.Fileupload control is built in control in ASP.net.
Here is the HTML Code.
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="jquery.js" type="text/javascript"></script> <script src="jquery.MultiFile.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <div> <asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" /> <br /> <asp:fileupload id="FileUpload2" runat="server" xmlns:asp="#unknown" /> <br /> <asp:fileupload id="FileUpload3" runat="server" xmlns:asp="#unknown" /> <br /> <asp:fileupload id="FileUpload4" runat="server" xmlns:asp="#unknown" /> </div> <asp:button id="btnUpload" runat="server" xmlns:asp="#unknown"> onclick="btnUpload_Click" Text="Upload Files"/><br /><br /> </form> </body> </html> </asp:button>
Code to save the files on Button click.
protected void btnUpload_Click(object sender, EventArgs e) { HttpFileCollection uploads = Request.Files; for (int fileCount = 0; fileCount < uploads.Count; fileCount++) { HttpPostedFile uploadedFile = uploads[fileCount]; string fileName = Path.GetFileName(uploadedFile.FileName); if (uploadedFile.ContentLength > 0 ) { uploadedFile.SaveAs(Server.MapPath("~/Files/") + fileName); lblMessage.Text += fileName + "Uploaded <br />"; } } }
Here the uploaded files are get saved into server,in yours case you can extract the details of file and save it to database.
Hope this one help.
Thanks.
[Edit member="Tadit"]
Formatted Text.
[/Edit]
这篇关于如何在将数据插入数据库之前在gridview中保存Fileupload详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文