【问题标题】:File Upload in database using fileupload control使用文件上传控件在数据库中上传文件
【发布时间】:2012-03-30 18:24:51
【问题描述】:

我在 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>

现在如何使用后面的代码访问文件上传控件中上传的文件路径并将其存储在数据库中

【问题讨论】:

标签: c# asp.net


【解决方案1】:

尝试:

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;

 }
} 

【讨论】:

    【解决方案2】:

    使用此代码:

    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.
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-16
      • 2016-11-10
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多