Click here to Skip to main content
15,915,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#



i want to store the path of image in data base but my this code is not working properly. here is my aspx.cs file code ......


C#
string path ="@~/users_images/" + File1.PostedFile.FileName;


        File1.PostedFile.SaveAs(Server.MapPath(path));
        objbll.Images = File1.PostedFile.FileName;




and here is the bll code ....


C#
public string Images
        {
            get { return images; }
            set { images = value; }
        }



SQL
param[11] = new SqlParameter("@images", SqlDbType.NVarChar);
           param[11].Value = Images;





and here is default.aspx code file ......


XML
<asp:GridView ID="grd_profile" runat="server" AutoGenerateColumns="False" Height="324px"
                    Width="428px" style="margin-right: 0px">


<Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <table style="width:100%;">
                            <tr>
                                <td style="width:100px;">
                                    <img height="200px" src = "<%#Eval("images")%>" width="200px"  alt = ""/>



                                </td> 

                        
                    
                
            








            <pre>
Posted
Updated 27-Jun-12 0:18am
v2

 
Share this answer
 
The mistake you are doing here is in your BLL code you are storing the client's file path.
Your code should go something like this
C#
string serverFilePath = Server.MapPath("@~/users_images/" + File1.PostedFile.FileName);
File1.SaveAs(serverFilePath);
objbll.Images = serverFilePath;
 
Share this answer
 
v2
Comments
Asim8748 27-Jun-12 12:00pm    
this code is working but it does not show the image in grid view .... How to show it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900