Click here to Skip to main content
15,897,704 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Permission Denied between ASP & ASP.Net Frames Pin
Christian Graus6-Jul-08 10:12
protectorChristian Graus6-Jul-08 10:12 
GeneralRe: Permission Denied between ASP & ASP.Net Frames Pin
SteveRicketts6-Jul-08 10:28
SteveRicketts6-Jul-08 10:28 
QuestionContinue Pin
kjosh6-Jul-08 4:55
kjosh6-Jul-08 4:55 
AnswerRe: Continue Pin
Parwej Ahamad6-Jul-08 7:11
professionalParwej Ahamad6-Jul-08 7:11 
Questionpic in database Pin
strawberrysh6-Jul-08 3:59
strawberrysh6-Jul-08 3:59 
AnswerRe: pic in database Pin
N a v a n e e t h6-Jul-08 4:13
N a v a n e e t h6-Jul-08 4:13 
QuestionRe: pic in database Pin
strawberrysh6-Jul-08 6:47
strawberrysh6-Jul-08 6:47 
AnswerRe: pic in database Pin
merinkmathew8-Jul-08 7:12
merinkmathew8-Jul-08 7:12 
PLS TRY THIS

IN HTML

<form id="form1" runat="server">
<div>
<div>
<div>
Image Title:<asp:TextBox ID="txtImgTitle" runat="server"></asp:TextBox>
</div>
<div>
Browse Image:<asp:FileUpload ID="fileImgUpload" runat="server" />
</div>
<div>
<asp:Button ID="btnUpload" runat="server" Text="Save" OnClick="btnUpload_Click" /></div>
</div>
<br />
<br />
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="5"
GridLines="None" ShowHeader="False" Width="394px" AllowPaging="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="imgSaved" runat="server" ImageUrl='<%# imageURL(DataBinder.Eval(Container.DataItem, "img_id").ToString()) %>'
AlternateText='<%#DataBinder.Eval(Container.DataItem,"img_title") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>

</div>
</form>



CODE


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
displayImages();
}
}

protected void btnUpload_Click(object sender, EventArgs e)
{
int imageSize;
string imageType;
Stream imageStream;

// Gets the Size of the Image
imageSize = fileImgUpload.PostedFile.ContentLength;

// Gets the Image Type
imageType = fileImgUpload.PostedFile.ContentType;

// Reads the Image stream
imageStream = fileImgUpload.PostedFile.InputStream;

byte[] imageContent = new byte[imageSize];
int intStatus;
intStatus = imageStream.Read(imageContent, 0, imageSize);

// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("insert into tbl_image(img_title,img_stream,img_type) values(@img_title,@img_stream,@img_type)", myConnection);

// Mark the Command as a Text
myCommand.CommandType = CommandType.Text;

// Add Parameters to Command
SqlParameter img_title = new SqlParameter("@img_title",SqlDbType.VarChar);
img_title.Value = txtImgTitle.Text;
myCommand.Parameters.Add(img_title);

SqlParameter img_stream = new SqlParameter("@img_stream", SqlDbType.Image);
img_stream.Value = imageContent;
myCommand.Parameters.Add(img_stream);

SqlParameter img_Type = new SqlParameter("@img_type", SqlDbType.VarChar);
img_Type.Value = imageType;
myCommand.Parameters.Add(img_Type);

try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();

Response.Redirect("upload.aspx");
}
catch (SqlException SQLexc)
{
Response.Write("Insert Failure. Error Details : " + SQLexc.ToString());
}

}

public void displayImages()
{
try
{
// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

myConnection.Open();
SqlCommand myCommand = new SqlCommand("select * from tbl_image", myConnection);

// Mark the Command as a Text
myCommand.CommandType = CommandType.Text;

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet);

GridView1.DataSource = myDataSet;
GridView1.DataBind();

myConnection.Close();
}
catch (SqlException SQLexc)
{
Response.Write("Data Retrival Failure. Error Details : " + SQLexc.ToString());
}
}

public string imageURL(string img_id)
{
return ("retrieveImages.aspx?id=" + img_id);
}
QuestionJoin tables in sqldatasource Pin
saquibsa6-Jul-08 2:03
saquibsa6-Jul-08 2:03 
AnswerRe: Join tables in sqldatasource Pin
Herman<T>.Instance8-Jul-08 4:00
Herman<T>.Instance8-Jul-08 4:00 
Questionobject not declared at runtime Pin
saquibsa6-Jul-08 2:02
saquibsa6-Jul-08 2:02 
GeneralRe: object not declared at runtime Pin
Guffa6-Jul-08 3:21
Guffa6-Jul-08 3:21 
QuestionOpenFileDialog Pin
two_man_only6-Jul-08 1:53
two_man_only6-Jul-08 1:53 
AnswerRe: OpenFileDialog Pin
Steve Westbrook6-Jul-08 16:01
Steve Westbrook6-Jul-08 16:01 
GeneralRe: OpenFileDialog Pin
two_man_only6-Jul-08 19:27
two_man_only6-Jul-08 19:27 
GeneralRe: OpenFileDialog Pin
Steve Westbrook7-Jul-08 1:42
Steve Westbrook7-Jul-08 1:42 
Questionhow to call a javascript function from javascript file in asp.net 2.0 Pin
vijaylumar5-Jul-08 20:21
vijaylumar5-Jul-08 20:21 
AnswerRe: how to call a javascript function from javascript file in asp.net 2.0 Pin
N a v a n e e t h6-Jul-08 3:08
N a v a n e e t h6-Jul-08 3:08 
Questiontimer in wepage Pin
Panks_macho5-Jul-08 20:20
Panks_macho5-Jul-08 20:20 
AnswerRe: timer in wepage Pin
N a v a n e e t h6-Jul-08 3:12
N a v a n e e t h6-Jul-08 3:12 
Questionprint problem Pin
lav naphade5-Jul-08 18:51
lav naphade5-Jul-08 18:51 
QuestionAccessdatasource control help plzz Pin
dream_liner_7e75-Jul-08 17:21
dream_liner_7e75-Jul-08 17:21 
AnswerRe: Accessdatasource control help plzz Pin
N a v a n e e t h5-Jul-08 18:10
N a v a n e e t h5-Jul-08 18:10 
QuestionAccessdatasource control help Pin
dream_liner_7e75-Jul-08 16:25
dream_liner_7e75-Jul-08 16:25 
AnswerRe: Accessdatasource control help Pin
N a v a n e e t h5-Jul-08 16:42
N a v a n e e t h5-Jul-08 16:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.