2012-03-30 10 views
0

Ich habe eine Fileupload-Steuerung und eine Bildsteuerung auf asp.net Seite wie folge:Datei-Upload in Datenbank mit Fileupload-Steuerelement

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

Nun, wie der Zugang des Filepath in dem Fileupload-Steuerelement hochgeladen bekommt hinter mithilfe von Code und speichern sie in der Datenbank

+0

http://www.c-sharpcorner.com/UploadFile/munnamax/FileUploader02102006073548AM/FileUploader.aspx Dieser Link muss hilfreich sein – ganesshkumar

Antwort

4

Versuch:

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; 

} 
} 
+1

Beat mich dazu :) +1 – ToddBFisher

+0

@ToddBFisher Vielen Dank. –

0

mit diesem Code:

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