0

I have a FileUpload Control and a image control on asp.net page as follows :

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

Now how to get access of the filepath uploaded in the fileupload control using code behind and store it in database

1

2 Answers 2

4

try:

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;

 }
} 
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.