Save Images in Access Database : ASP.NET

Using OLE Object we can save images in Access Database, in this example we will select a image and save that image in Access database using ASP.NET.

First we will start creating a table in access database.

Create a table ImageTable with following fields

  1. ID    AutoNumber (Primary Key)
  2. ImageName   Text
  3. ImageValue OLE Object

Now create a WebApplication and add following controls on the Web Form

  1. Upload Control
  2. Button for uploading image and saving into database
  3. DropdownList for listing all the images in Dabase Table
  4. Button for saving the image into a folder
  5. Image to show the image save on the disk

html

Initially we will fetch the image names which are already saved in the table and show in the drop down list,  for that use Page_Load method and insert following code

Page_Load

now double click on upload image button and add following code, in following code we are just reading the image into stream of bytes and we are storing into the database

UploadImage

To resave the image on to the disk we will use following code, once we save image from database to disk we will show that image in image1 control.

SaveImage

now we are ready with our code just build, run and test

hope this helps

Tags: Save images in Access Database, ASP.NET, Save images in Database

HttpWebRequest & HttpWebResponse

Following example I am trying to explain how we can request to a URL from our coding and read the Header content of the response.

 

Create a web application and add a Textbox and a Button to Default.aspx and double click on the button and add following code.

 

        protected void Button1_Click(object sender, EventArgs e)

        {

            try

            {

                //Create a object for HttpWebRequest using this request object we will

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(TextBox1.Text);

                //request a response from the URL

                HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                //Reading all header content of response

                for (int i = 0; i < res.Headers.Count; i++)

                {

                    Response.Write(res.Headers.AllKeys[i] + ” : “ + res.Headers[i].ToString() + “<br>”);

                }

            }

            catch (Exception ex)

            {

                //Catch if there are any exception

                Response.Write(ex.Message);

            }

        }

 

Now we are ready with code, lets build, run and test

 

Hope this helps.

 

SatishKumar J

Microsoft MVP(ASP.NET)

 

Tags : HttpWebRequest, HttpWebResponse, Headers

ASP.NET AJAX and Calendar Control

Normally when we use calendar control in asp.net we see that calendar control occupies lot of space and selecting a date will cause a post back.

To avoid that problem we can use AJAX to select a date from calendar control with out any page post back and hiding the calendar control will save lot of space.

Now lets create a web application and add a script manager and a update panel control, now under update panel add  text box, button and a calendar control as shown the below screen shot and make calendar control visible property to false

image

Now lets write logic in .cs file for that double click on Button and add following code

Calendar1.Visible = true;

and double click on calendar control and add following code

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
    Calendar1.Visible = false;
}

 

Now we are ready with our code, lets run build and test.

 

image

 

Hope this helps.

 

ASP.NET MVC 1.0 is now Live

ASP.NET is now live and you can download that from http://go.microsoft.com/fwlink/?LinkId=144444 and you can access the documentation from http://go.microsoft.com/fwlink/?LinkId=145989.

 

Tags : ASP.NET MCV, .NET C#, ASP.NET 3.5

External Images in .rdlc Reports : ASP.NET

In this example I will explain how we can use external images in .rdlc reports.Create a Web Application.

Right click on Project in Solution Explorer –> Add New Item – Select a .rdlc Report

image

Now Drag and Drop a image control in Header section in the Report.rdlc

Go to Report Menu in Visual Studio and Select Report Parameters –> and Add a parameter with name Path

image

Now we will set this path parameter to our image’s value property and provide the value at run time, select image and properties(F4) and set following values to Source and Value properties

Source = External and Value = !Path.value

image

Now create a Image folder in your solution and Add some images to that folder.As I am only concentration on showing images on the report in this example I am not loading any data on to the report.

Now open Default.aspx page and add MicrosoftReportViewer Control and set MicrosoftReportViewer control source to Report1.rdlc

image

Now we are ready with design part,

One of the most important thing while displaying external images is to set EnableExternalImages perperty of MicrosoftReportViewer.LocalReport’s to True, this will allow us to show external images on the .rdlc reports

And also we need to set the Path parameter value so that image will be displayed on the report for that we need to all following code to Page_Load event

image 

Now we are ready with our code, just build and run and test

image

Hope this helps.

Tags : .rdlc report, external Images, ASP.NET

Microsoft Implementation of Web 2.0 : Kobe

Web 2.0 much discussed term nowadays; what is Web 2.0 lets us first define what Web 1.0 and then come to Web 2.0.

Web 1.0: Normal web applications which provide some information and very minimal user interaction with the application, this is server centric

Web 2.0: A rich Web application which provides more interactions with user, and user can customize his content etc, and this is user centric.
One of the examples for Web 2.0 is twitter.com, in this web site you can share photos, customize view etc.

Microsoft has come with some starter kit for implementing Web 2.0 applications and it is called Kobe.

They are providing some good information how to plan and build Web 2.0 application, you can find more details, examples and some videos at following link.

http://msdn.microsoft.com/en-us/architecture/bb194897.aspx

ASP.NET 3.5 AJAX Example

In this example I am Using AJAX to show how you can display data using AJAX.This will work very fast and you will see there is not page reload is occurring

Create a Web Application and modify Default.aspx html content
I am adding Script manager control and a Update Panel control, Under Update panel control add 2 labels and 2 dropdownlist control and gridview like below

Once Modify Default.aspx, open Default.aspx.cs and modify the Page_Load and add following code.

Now we will add code to fetch the Orders by particular Employee, for that we need write code in DropDownList1_SelectedIndexChanged event, please add following code

Now we will fetch the order details of selected order number for that we need to add the following code in DropDownList2_SelectedIndexChanged event

Now we are ready with over code, just build, run and test
Hope this help you.