[英]File Upload in database using fileupload control
我在asp.net頁面上有一個FileUpload控件和一個圖像控件,如下所示:
<tr>
<td> </td>
<td align="left">
<asp:Image ID="profileimage" runat="server" ImageUrl="~/Images /images2.jpg"
Width="150px" Height="150px" />
</td>
<td> </td>
<td colspan="2" align="left">
<asp:FileUpload ID="Fu" runat="server" Width="550px" />
</td>
</tr>
現在,如何使用后面的代碼訪問在fileupload控件中上載的文件路徑並將其存儲在數據庫中
嘗試:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Fu.HasFile) {
string filepath = Fu.PostedFile.FileName;
//save the file to the server
Fu.PostedFile.SaveAs(Server.MapPath(".\\") + file);
lblStatus.Text = "File Saved to: " + Server.MapPath(".\\") + file;
}
}
使用此代碼:
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (UploadedFile upload in Fu.UploadedFiles)
{
Fu.TargetFolder = "/Attachment/ClientProfile";
path = Server.MapPath(Fu.TargetFolder) + "\\" + upload.GetName();
upload.SaveAs(path);
}
//Here give ImageName=path to save in database.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.