My Linux Stuff - Complete Blog For Linux Articles

My Linux Stuff - Complete Blog For Linux Articles

A Website For Complete Linux OS,Step by Step linux Installtion, Linux Tips and Tricks and Linux Stuff and so on... Connect and sharing here....

TOP 50 ENGINEERING COLLEGES IN INDIA 2014

TOP 50 ENGINEERING COLLEGES IN INDIA 2014

This below survey was taken many form many colleges in India. These Top 50 Engineering Colleges in India have Good Infrastructure, Good Environment, Educations , Staff, Placement , Research Activities and other Facilities are good.

Top 10 Government Engineering Colleges in India

Top 10 Government Engineering Colleges in India

These Government Engineering Colleges in India are really good for all kind of stuff like Education , research , Placement and New Innovation Ideas etc... But Getting seat in these colleges are heavy competition in students .....

Top 10 Colleges In India 2014

Top 10 Colleges In India 2014

Indian Institute Of Technology Delhi,Indian Institute Of Technology Bombay,Indian Institute Of Technology Kanpur,Indian Institute Of Technology Madras,Indian Institute Of Technology Kharagpur,Indian Institute Of Technology Roorkee,University Of Delhi,Indian Institute Of Technology Guwahati,University Of Calcutta,University Of Mumbai, National Institute Of Technology,Trichy.

2014 LATEST SURVEY TOP RANKING ENGINEERING COLLEGES IN INDIA

2014 LATEST SURVEY TOP RANKING ENGINEERING COLLEGES IN INDIA

This below survey was taken many form many colleges in India. These Top 100 Engineering Colleges in India have Good Infrastructure, Good Environment, Educations , Staff, Placement , Research Activities and other Facilities are good. If you want to do Engineering as your dream and try out these colleges

Subscribe Now!

Enter your email address:

Wednesday, December 29, 2010

Saving images into the database in asp.net and displaying to the GridView


Introduction


This article has been written in the response of the question asked in this Forum thread http://www.dotnetfunda.com/forums/thread2974-explanation-about-ashx-pagehandler-page-with-example.aspx where the author was able to save the image into database successfully but couldn't show the record into the GridView.

Namespace used in this article

You will need to use System.IO, System.Configuration, System.Data, System.Data.SqlClient namespaces in order to achive the solution described in this article.

ImageUpload Database table structure

In order to show how to save and read the image from database, I have created a sample table and its strucure similar to below mentioned table.



Here my AutoId column is autoincrement column and rest of the columns are self explained in the picture. One thing to note is that PictureFilecolumn is of Image data type.
To show the saving and displaying image from database, I have created 3 pagese
  1. default.aspx - to save the image into the database
  2. ShowImage.aspx - to show the records including the image into the gridview
  3. ShowImage.ashx (Generic Hanlder file) - to retrive the image from the database and give it to ShowImage.aspx as Binary data to its html img tag


Saving image to the database in asp.net


The code to save the image into the database is written in default.aspx in my sample app and here is the code for the default.aspx page

Select file to save into the database:
<asp:FileUpload runat="server" ID="FileUpload1" />
<asp:Button runat="server" ID="btnSave" OnClick="SaveToTheDatabase" Text="Save to the database" />
<p><asp:Label ID="lblMessage" runat="server" EnableViewState="false" /></p>

Notice that when Save ... button will be clicked, I have fired SaveToTheDatabase method and below is the code snippet for this method.

protected void SaveToTheDatabase(object sender, EventArgs e)
{
string fileName = FileUpload1.PostedFile.FileName;
int fileLength = FileUpload1.PostedFile.ContentLength;
byte[] imageBytes = new byte[fileLength];
FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, fileLength);
string connStr = ConfigurationManager.AppSettings["ConnStr"].ToString();
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "INSERT INTO ImageUpload (PictureName, PictureFile) VALUES (@pictureName, @pictureFile)";
SqlParameter[] prms = new SqlParameter[2];
prms[0] = new SqlParameter("@pictureName", SqlDbType.VarChar, 50);
prms[0].Value = fileName;
prms[1] = new SqlParameter("@pictureFile", SqlDbType.Image);
prms[1].Value = imageBytes;
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(prms);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
lblMessage.Text = "Picture uploaded successsfully !";
}
}

In the above code snippet, first I have retrieved the complete file name of the image, then retrieved the length of the image content usingPostedFile.ContentLength property of FileUpload control.
The next line is to create the array of bytes and read the entire image into it.
Rest of the code snippets are self explanatory in which I have used ADO.NET to save the records into the database. One important thing to note is that as my PictureFile column is of type Image I will have to specify the Image data type of SqlDbType in the SqlParameter.
This way we have saved the image into the database successfully, now lets try to read the image from the database in the next page.

Show image from database into GridView

I am displaying the image from the database into ShowImage.aspx page and here is the code for that.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="AutoID" DataField="AutoID" />
<asp:BoundField HeaderText="Picture Name" DataField="PictureName" />
<asp:TemplateField HeaderText="Picture">
<ItemTemplate>
<img src="ShowImage.ashx?autoid=<%# Eval("AutoId").ToString() %>" width="150" height="100" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Notice ItemTemplate code for the Picture column, I have used an img tag and specified its src attribute as a generic handler file (.ashx) that I am going to describe later in this article.
Below is the code for the code behind of the ShowImage.aspx page

protected void Page_Load(object sender, EventArgs e)
{
string connStr = ConfigurationManager.AppSettings["ConnStr"].ToString();
DataTable table = new DataTable();
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "SELECT AutoID, PictureName FROM ImageUpload ORDER BY PictureName";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
{
conn.Open();
ad.Fill(table);
conn.Close();
}
}
}
GridView1.DataSource = table;
GridView1.DataBind();
}

In the above code snippet, I have used ADO.NET to retrive the records of the ImageUpload table and bounded to the GridView.
As I had specified ShowImage.ashx generic handler (.ashx) as src attribute of the img tag in the Picture column of GridView, so lets write code for this handler file.

public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["autoId"] == null) return;
string connStr = ConfigurationManager.AppSettings["ConnStr"].ToString();
string pictureId = context.Request.QueryString["autoId"];
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand("SELECT PictureFile FROm ImageUpload WHERE AutoID = @autoId", conn))
{
cmd.Parameters.Add(new SqlParameter("@autoId", pictureId));
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
reader.Read();
context.Response.BinaryWrite((Byte[])reader[reader.GetOrdinal("PictureFile")]);
reader.Close();
}
}
}
}
public bool IsReusable
{
get
{
return true;
}
}


In the above code snippet, I am checking for the autoId querystring, if its null I am simply returning.
Next line is to get the querystring value, retrive the image content from the database (PictureFile column) and writing it as Binary. The IsReusablemethod is the default method that comes with the generic handler, I have changed its return type to true so that same can be reused.
If you have followed the steps I have described above you should be ready to run the application. Run it and start saving records into the database (default.aspx), go to the ShowImage.aspx page and you should be able to see images in the GridView.

Conclusion

Hope this will be useful for the author of the Forum thread for which I have written this article; apart from that this should be useful for others who are looking for solution of saving images into the database and showing into the Grid.
Thanks for reading!

Mandriva Linux OS Download


Mandriva Linux is a community-based Linux distribution, suitable for a wide range of situations from typical desktop use through development and server roles up to clustering.
Mandriva Linux is based on the Cooker development project sponsored by Mandriva. Hundreds of passionate free software developers work openly on the core of the distribution. This open, community-driven development system has been in place since 1998, making it one of the longest-standing open source development communities around. The involvement of the Mandriva development community helps us to make Mandriva Linux one of the largest, most up-to-date, integrated, internationalized and standardized distributions available.



Mandriva Linux OS Download

TOP 10 DREAM COMPANIES TO WORK FOR?

Best 10 DREAM COMPANIES TO WORK FOR?

We have thousands of companies with good market value and with good reputation. But what matters most is working with the best.
In other words, Best among the best. So here it is, the list of top 10 companies that a person should dream to work on. If you are already working in any one of the companies listed below then dude your the luckiest person alive on planet. The reason is simple, it is not easy for a person to just walk into the companies and demand job.
You should have an experience of atleast 10 to 15 years to be considered a job posting in the said companies.

The top 10 are:
TOP 10 DREAM COMPANIES TO WORK FOR?
1. Google
2. Virgin
3. Self-employment


4. Apple
5. Qantas
6. Walt Disney
7. OMD
8. Sydney Water
9. Getaway
10. Facebook

TOP 10 DREAM COMPANIES TO WORK FOR?

FRESHERS WALK-IN : PHP PROGRAMMERS @ HYDERABAD FOR THE POSITION AS PHP PROGRAMMER


Our Web Studio is a leading professional website design, ecommerce and software development organization offering varied web and software services.
Freshers : Scheduled Walk-In : PHP Programmers @ Hyderabad
Job Position : PHP Programmer
Job Category : IT / Software
Job Location : Hyderabad, Andhra Pradesh
Number of Vacancies : 4
Desired Qualification : B.Sc – Computers
• BE/B.Tech. – Computers
• BCA – Computers
• M.Sc – Computers
• M.Tech – Computers
• MCA – Computers
Desired Experience : 0-1 Years
Mandatory Skills : PHP, MySql
Desired Skills :
• We currently have multiple vacancies for PHP Programmers.
• Freshers are welcome and should have strong command over C, C++ and SQL.
Job Description :
• Working along with the project manager to understand project requirements.
• Develop the programming code from scratch or by adapting existing application to meet business requirements.
• Testing the application and identifying any technical problems.
Compensation : Salary will be commensurate with skills and performance and will not be a limiting factor for the right candidate.
Interview Date : Interested candidates can call to fix the appointment for interview.
Interview Venue :
Our Web Studio Software Solutions Pvt Ltd,
6-3-666/A, 4th Floor, Lumbini Towers,
Opp: NIMS, Panjagutta,
Hyderabad
Contact Person : Farheen
Contact Number : +91-40-66754011

WIPRO FRESHERS OFF-CAMPUS FOR BE / B.TECH / MCA / ME / M.TECH : 2010 / 2009 PASSOUT @ KERALA


WIPRO Technologies are conducting an offcampus for BE/B.Tech 2009/2010 batch via Shreds @ Kerala.

Walk-In Date : On 8th January 2011 (Saturday)
Walk-In Venue :
[Await Details],
Ernakulam
Eligibility Criteria :
• Year of Graduation: 2009, 2010 batch.
• BE / B.Tech / ME / M.Tech (All branches) / MCA.
• 50% in X, XII, 60% in UG & PG.
• No standing arrears on the day of interview.
• Maximum gap of 2 years between the academics.
• Candidates who have studied outside Kerala colleges are also eligible.
• Candidates who attended Wipro INTERVIEW in the past 6 months are not eligible.
• Candidates who wrote the test and did not clear the test / attend interview are ELIGIBLE.
Selection Process :
• Written Test
• Technical & HR Interviews
Confirmation / Hall Ticket :
• Online Confirmation open
• SHREDS [Login / New Registration] to confirm / access hall ticket.
• Hall Tickets will be available in SHREDS Login within 24 hours from confirmation
All the candidates should bring the following to test venue :
• Writing Pad.
• Two copies of RESUME.
• Two sets of photocopies of your mark lists.
• Three copies of passport size photographs.
• Rs.100/- to be paid to SHREDS towards examination fees.
• Gum / Stapler.
• Any Photo ID [College, DL, PAN, Voters].

TOP 10 SOFTWARE COMPANIES IN INDIA 2010

TOP 10 SOFTWARE COMPANIES IN INDIA 2010
TOP 10 SOFTWARE COMPANIES IN INDIA 2010


SOFTWARE COMPANIES IN









1 Tata Consultancy Services Ltd.
2 Infosys Technologies Ltd.
3 Wipro Technologies Ltd.
Mahindra Satyam .
5 HCL Technologies Ltd.
6 Patni Computer Systems Ltd.
7 I-flex Solutions Ltd.
8 Tech Mahindra Ltd. (formerly Mahindra-British Telecom Ltd.
9 Perot Systems TSI (I) Ltd.
10 L&T Infotech Ltd.
11 Polaris Software Lab Ltd.
12 Hexaware Technologies Ltd.
13 Mastek Ltd.
14 Mphasis BFL Ltd.


15 Siemens Information Systems Ltd.
16 Genpact
17 i -Gate Global Solutions Ltd.
18 Flextronics Software Systems Ltd. (Standalone for FSS)
19 NIIT Technologies Ltd.
20 Covansys India Ltd.

TOP 10 SOFTWARE COMPANIES IN INDIA 2010

A Top 10 extract of the world's largest software companies according to the Forbes Global 2000





  • Apple



  • IBM



  • Microsoft



  • Google



  • Accenture



  • SAP AG



  • Hewlett Packard



  • Computer Sciences Corporation



  • Yahoo!



  • CA

  • A Top 10 extract of the world's largest software companies according to the Forbes Global 2000

    Aptitude Questions and Answers In Online

    Related Posts Plugin for WordPress, Blogger...