
Requirement:
- Create a Directory dynamically, if it does not exist.
- Store the Images to the Folder.
- Store the Image Path to the Database.
Database Table
- create table ImageUpload
- (
- Sr_No int identity,
- Pictures varchar(500)
- )
- <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Image_Saving_To_SQL_Using_ServerMapPath.aspx.cs" Inherits="Image_Saving_To_SQL" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
- <style type="text/css">
- .Heading
- {
- font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; font-style: normal;
- font-variant: normal; text-transform: capitalize; color: #808080;
- text-align:center;
- height:30px;
- padding-top:15px;
- margin:10px;
- background-color:Gray;
- }
- .Content
- {
- margin:10px;
- height:400px;
- }
- .style1
- {
- width: 545px;
- }
- .style2
- {
- width: 151px;
- }
- .style3
- {
- width: 126px;
- }
- </style>
- </asp:Content>
- <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
- <div style="height: 783px">
- <div class="Heading">
- Saving Image To Database</div>
- <div class="Content">
- <br />
- <table style="width:100%;">
- <tr>
- <td class="style3">
- </td>
- <td class="style1">
- <asp:Image ID="Image1" runat="server" Height="293px" Width="584px" />
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="style3">
- </td>
- <td class="style1">
- <asp:FileUpload ID="FileUpload1" runat="server" />
- <asp:Button ID="btnUpload" runat="server" BackColor="#009933" Font-Bold="True"
- ForeColor="White" Height="30px" onclick="btnUpload_Click" Text="Upload"
- Width="100px" />
- <asp:Button ID="btnSave" runat="server" BackColor="#009900" Font-Bold="True"
- ForeColor="White" Height="30px" onclick="btnSave_Click" Text="Save"
- Width="100px" />
- </td>
- <td>
- </td>
- </tr>
- <tr>
- <td class="style3">
- </td>
- <td class="style1">
- <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
- </td>
- <td>
- </td>
- </tr>
- </table>
- </div>
- </div>
- </asp:Content>



Join the conversation! Your thoughts help the community grow.