簡體   English   中英

使用文件上傳控件在數據庫中上傳文件

[英]File Upload in database using fileupload control

我在asp.net頁面上有一個FileUpload控件和一個圖像控件,如下所示:

<tr>
                <td>&nbsp;</td>
                <td align="left">
                     <asp:Image ID="profileimage" runat="server" ImageUrl="~/Images /images2.jpg" 
                     Width="150px" Height="150px" />
                </td>
                <td>&nbsp;</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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM